我目前正在使用Swift 2.0和Xcode Beta 2开发我的第一个iOS应用程序.它读取外部JSON并在数据表格视图中生成列表.但是,我得到一个奇怪的小错误,我似乎无法修复:
Extra argument 'error' in call
Run Code Online (Sandbox Code Playgroud)
这是我的代码片段:
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()
})
}
}
})
Run Code Online (Sandbox Code Playgroud)
此行引发错误:
if let jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &err) as? NSDictionary{
Run Code Online (Sandbox Code Playgroud)
有人可以告诉我这里我做错了什么吗?