Ich habe diesen CodeVersuch NSJSONSerialization.JSONObjectWithData auf Swift 2
let path : String = "http://apple.com"
let lookupURL : NSURL = NSURL(string:path)!
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithURL(lookupURL, completionHandler: {(data, reponse, error) in
let jsonResults : AnyObject
do {
jsonResults = try NSJSONSerialization.JSONObjectWithData(data!, options: [])
// success ...
} catch let error as NSError {
// failure
print("Fetch failed: \(error.localizedDescription)")
}
// do something
})
task.resume()
zu verwenden, aber es mit dem Fehler auf der let task
Linie versagt:
invalid conversion from throwing function of type (__.__.__) throws to non throwing function type (NSData?, NSURLResponse?, NSError?) -> Void
, was falsch ist? Dies ist Xcode 7 beta 4, iOS 9 und Swift 2.
edit:
das Problem mit diesen Linien
do {
jsonResults = try NSJSONSerialization.JSONObjectWithData(data!, options: [])
// success ...
} catch let error as NSError {
// failure
print("Fetch failed: \(error.localizedDescription)")
}
entferne ich diese Zeilen und die let task
Fehler zu sein scheint, verschwindet .