請注意,我已經嘗試了很多像this這樣的解決方案,但都沒有工作。無法用類型爲'(configuration:URLSessionConfiguration)'的參數列表調用'URLSession''
這裏是screenshot和代碼;
func downloadItems() {
let urlE: String = "http://alicelik.me/forios/service.php"
guard let url = URL(string: urlE) else {
print("Error: cannot")
return
}
let configuration = URLSessionConfiguration.default
var session = URLSession(configuration: configuration)
let task = session.dataTask(with: url as URL){
(data, response, error) in
guard error == nil else {
print("error calling GET on /todos/1")
print(error)
}
return()
}
task.resume()
}
這裏是URLSession func;
@nonobjc func URLSession(session: URLSessionConfiguration, dataTask: URLSessionDataTask, didReceiveData data: NSData) {
self.data.append(data as Data);
}
@nonobjc func URLSession(session: URLSessionConfiguration, task: URLSessionTask, didCompleteWithError error: NSError?) {
if error != nil {
print("Failed to download data")
}else {
print("Data downloaded")
self.parseJSON()
}
}
注:* URLSession和* URLSessionConfiguration在FUNC URLSession(會話*)給予同樣的錯誤。
它在我的Xcode上工作得很好! –
嘗試使用新的func代碼。它會告訴你現在錯誤。我先忘了。 – Ali
它不應該防範**讓**錯誤? – Honey