【发布时间】:2016-02-23 17:46:41
【问题描述】:
我在以下几行中遇到错误...
let taskData = session.dataTaskWithRequest(request, completionHandler: { ( data: NSData!, reponse:NSURLResponse!, error: NSError!) -> Void in
let parsedStores = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: &parseError) as! NSDictionary
if let stores: AnyObjec = parsedStores["Stores"]
这段代码可以在 IOS8 上为我工作,我将语法转换为最新的 Swift 语法,但它给我留下了这些错误,我试图专门针对语法编辑器上的错误区域,但它仍然没有不修。请帮我摆脱这些。谢谢
函数代码。
func loadRecords()
{
let urlString = "http://google.com"
let config = NSURLSessionConfiguration.defaultSessionConfiguration()
let session = NSURLSession(configuration: config, delegate: nil, delegateQueue: nil)
//Create the URL Object
if let url = NSURL(string: urlString)
{
// Create the request object
let request = NSURLRequest(URL: url)
// execute the request
let taskData = session.dataTaskWithRequest(request, completionHandler: { ( data: NSData!, reponse:NSURLResponse!, error: NSError!) -> Void in
// Do something with the data back
if (data != nil)
{
//get some data back
print("\(data)")
var parseError:NSError?
let parsedStores = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: &parseError) as! NSDictionary
println("JSON Data \n \(parsedStores)")
if let stores: AnyObjec = parsedStores["Stores"]
{
self.parseJSON(stores)
}
} else
{ //we got an error
print("Error getting stores: \(error.localizedDescription)")
}
})
taskData.resume()
【问题讨论】:
-
错误说明了什么?
-
Cannot convert value type (NSDATA!, NSURLRESPONSE,NSERROR) to expected argument type (NSDATA?, NSURLRESPONSE?, NSERROR?)
标签: json swift web-services swift2 nsurl