【发布时间】:2016-07-09 13:00:21
【问题描述】:
我想跳过去使用 Xcode 7.3.1 并转换我的代码,但我在这里遇到了一些问题,这就是我过去在 Swift 1.1 中使用它的方式,但我收到错误 - 条件初始化器binding 必须具有 Optional 类型,而不是 '[NSObject: AnyObject]' SwiftyJSON:
if let userInfo = error.userInfo { <-- Error in this line //Initialiser for conditional binding must have Optional type, not '[NSObject: AnyObject]'
if let breadcrumb = userInfo["JSONErrorBreadCrumbKey"] as? NSString {
let newBreadCrumb = (breadcrumb as String) + "/\(index)"
let newUserInfo = [NSLocalizedDescriptionKey: "JSON Keypath Error: Incorrect Keypath \"\(newBreadCrumb)\"",
"JSONErrorBreadCrumbKey": newBreadCrumb]
return JSONValue.JInvalid(NSError(domain: "JSONErrorDomain", code: 1002, userInfo: newUserInfo))
}
}
提前致谢!
【问题讨论】:
-
error.userInfo是非可选的。删除if和大括号 -
感谢成功!!
标签: ios swift swift2 swifty-json