【发布时间】:2015-09-13 10:14:03
【问题描述】:
我目前正在使用 Swift 2.0 和 Xcode Beta 2 开发我的第一个 iOS 应用程序。它读取外部 JSON 并在表格视图中生成包含数据的列表。但是,我遇到了一个似乎无法修复的奇怪小错误:
Extra argument 'error' in call
这是我的代码的 sn-p:
let task = session.dataTaskWithURL(url!, completionHandler: {data, response, error -> Void in
print("Task completed")
if(error != nil){
print(error!.localizedDescription)
}
var err: NSError?
if let jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &err) as? NSDictionary{
if(err != nil){
print("JSON Error \(err!.localizedDescription)")
}
if let results: NSArray = jsonResult["results"] as? NSArray{
dispatch_async(dispatch_get_main_queue(), {
self.tableData = results
self.appsTableView!.reloadData()
})
}
}
})
在这一行抛出错误:
if let jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &err) as? NSDictionary{
谁能告诉我我在这里做错了什么?
【问题讨论】:
-
这条线没有给出这个错误,我想可能是因为你进入了不同的线。
-
使用 2.0,您需要创建一个
docatch块。error不再是NSJSONSerialization的参数。这个问题还有很多其他的答案。寻找做,抓住 Swift 2.0
标签: ios swift2 xcode7-beta2