1
編譯錯誤,目前我正在試圖通過此示例應用程序,以瞭解雨燕2.0和OAuth整合:https://github.com/soundcloud/iOSOAuthDemo調用中的額外參數'錯誤'。在雨燕2.0
下面的下面的片段引起了我的問題,導致應用程序在編譯失敗。
private func requestMe(token: String) {
let url = NSURL(string: "https://api.soundcloud.com/me.json?oauth_token=\(token)")!
let request = NSURLRequest(URL: url)
let session = NSURLSession(configuration: NSURLSessionConfiguration.defaultSessionConfiguration(),
delegate: nil, delegateQueue: NSOperationQueue.mainQueue())
let dataTask = session.dataTaskWithURL(url) { (data, response, error) -> Void in
if let jsonOutput = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: nil) as? [String:AnyObject] {
self.displayMe(jsonOutput)
}
}
dataTask.resume()
}
但是編譯我的錯誤處理時,看起來好像在這個版本斯威夫特(2.0)的改變,並導致以下錯誤:
Extra argument 'error' in call with the compilation.
我已經審查了這下面的堆棧發佈問題:Swift: Extra argument 'error' in call
和調整我的代碼,試圖糾正錯誤處理這樣的:
let dataTask = session.dataTaskWithURL(url) { (data, response, error) -> Void in
if let jsonOutput = NSJSONSerialization.JSONObjectWithData(data, options: nil) as? [String:AnyObject] {
self.displayMe(jsonOutput)
}
}
catch let error as NSError {
print(error);}
dataTask.resume()
}
我也試圖改變:
(data, options: nil, error: nil)
到
(data:NSData?, error:NSError?)
然而這些都不解決問題。有人可以指導我,這個錯誤處理可能是一個愚蠢的錯誤。
在此先感謝!
感謝您了埃裏克·d! – user4657
不客氣。 :) – Moritz