gpt4 book ai didi

ios - XCode 7/Swift 2 的字典类型速记语法错误

转载 作者:行者123 更新时间:2023-11-28 09:04:02 25 4
gpt4 key购买 nike

enter image description here

XCode 7/Swift 2 在此代码上吐出一堆错误,这些错误基于 Alamofire readme 中的片段。 .我对 Swift 或 iOS 开发一无所知,所以任何指点都将不胜感激。

import Foundation
import Alamofire

enum PTVRouter: URLRequestConvertible {
static let baseUrl = "http://timetableapi.ptv.vic.gov.au/"
static let devId = "__CENSORED__"
static let devKey = "__CENSORED__"

case HealthCheck()

var URLRequest: NSURLRequest {
let (path: String, parameters: [String: AnyObject]?) = {
switch self {
case .HealthCheck():
return ("/v2/healthcheck", ["devId": PTVRouter.devId])
}
}()

let URL = NSURL(string: PTVRouter.baseUrl)!
let URLRequest = NSURLRequest(URL: URL.URLByAppendingPathComponent(path))
let encoding = Alamofire.ParameterEncoding.URL

return encoding.encode(URLRequest, parameters: parameters).0
}
}

最佳答案

您不能就地指定元组 (path, parameters) 的类型。您必须在其他地方指定类型:

在闭包的开头:

let (path, parameters) = {() -> (String, [String:AnyObject]?) in
switch self {
case .HealthCheck():
return ("/v2/healthcheck", ["devId": PTVRouter.devId])
}
}()

或作为名称后的元组类型:

let (path, parameters) : (String, [String:AnyObject]?) = {
switch self {
case .HealthCheck():
return ("/v2/healthcheck", ["devId": PTVRouter.devId])
}
}()

请注意,在我看来,语法真的非常丑陋,并且在很大程度上混淆了代码的实际工作。

关于ios - XCode 7/Swift 2 的字典类型速记语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31220196/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com