自从我升级到 Xcode 7 beta 后,我遇到了一个无法修复的错误。这是我的 DataManager.swift 的完整代码
import Foundation
var TopAppURL:String = String()
var numberAsked:String = String()
class DataManager {
class func getInfo(ID : String){
TopAppURL = "http://sweetapi.com/?=\(ID)"
numberAsked = ID
}
class func loadDataFromURL(url: NSURL, completion:(data: NSData?, error: NSError?) -> Void) {
var session = NSURLSession.sharedSession()
// Use NSURLSession to get data from an NSURL
let loadDataTask = session.dataTaskWithURL(url, completionHandler: { (data: NSData!, response: NSURLResponse!, error: NSError!) -> Void in
if let responseError = error {
completion(data: nil, error: responseError)
} else if let httpResponse = response as? NSHTTPURLResponse {
if httpResponse.statusCode != 200 {
var statusError = NSError(domain:"com.raywenderlich", code:httpResponse.statusCode, userInfo:[NSLocalizedDescriptionKey : "HTTP status code has unexpected value."])
completion(data: nil, error: statusError)
} else {
completion(data: data, error: nil)
}
}
})
loadDataTask.resume()
}
class func getDataFromSweetApiOk(success: ((IDdata: NSData!) -> Void)) {
//1
print("DataManager loads \(TopAppURL)")
loadDataFromURL(NSURL(string: TopAppURL)!, completion:{(data, error) -> Void in
//2
if let urlData = data {
//3
success(IDdata: urlData)
}
})
}
}
所以我收到了这个错误:“无法使用类型为'(NSURL,completionHandler:(NSData!,NSURLResponse!,NSError!)-> Void)'的参数列表调用'dataTaskWithURL'”我到处搜索如何解决这个问题,但就像Swift一样2.0很新,没找到解决办法。