我收到错误“额外参数”错误“在电话中”我的代码是:
var urlData: NSData? = NSURLConnection.sendSynchronousRequest(request, returningResponse:&response, error:&reponseError)
答案 0 :(得分:0)
Swift不再使用作为参数传入的错误变量。改为使用do / catch块:
var urlData: NSData?
let request = NSURLRequest() // Presumably declared already
var response: NSURLResponse? // Presumably declared already
do {
urlData = try NSURLConnection.sendSynchronousRequest(request, returningResponse:&response)
}
catch let error as NSError {
print("Error: \(error.localizedDescription)")
}
另请注意,sendSynchronousRequest
已弃用,您可能应将其更改为dataTaskWithRequest(request: NSURLRequest) -> NSURLSessionDataTask
。