不清楚您要问 的 是什么 ,但我注意到您在代码中有几个错误:
您应该创建
session
使用NSURLSession(configuration: config)
session.dataTaskWithRequest
返回NSURLSessionDataTask
,因此无需将其包装在内部NSURLSessionDataTask()
(也称为实例化新NSURLSessionDataTask
对象)。完成处理程序是一个闭包,下面是创建该特定闭包的方法:
{(data: NSData!, response : NSURLResponse!, error : NSError!) in// your pre}
这是更新的代码:
let url = NSURL(string: "https://itunes.apple.com/search?term=(searchTerm)&media=software")let request = NSURLRequest(URL: url)let config = NSURLSessionConfiguration.defaultSessionConfiguration()let session = NSURLSession(configuration: config)let task = session.dataTaskWithRequest(request, completionHandler: {(data, response, error) in // notice that I can omit the types of data, response and error // your pre});// do whatever you need with the task e.g. runtask.resume()


