您好我刚刚完成了对Swift 3.0的转换,并且返回了很多错误。第一个是:
对成员'dataTask(with:completionHandler:)'
的模糊引用
找到这个候选人
有没有人有解决方案?
提供此代码的代码是:
let task = session.dataTask(with: request) {
(
data, response, error) in
guard let _:Data = data, let _:URLResponse = response , error == nil else {
print(data)
print("error")
return
}
_ = NSString(data: data!, encoding: String.Encoding.utf8)
//print(dataString)
}
答案 0 :(得分:9)
尝试这样的事情
guard let requestUrl = URL(string:yourUrlString) else { return }
let request = URLRequest(url:requestUrl)
let task = session.dataTask(with: request) {
(data, response, error) in
if error == nil {
//JSONSerialization
}
}