swift2 - How to use NSURLSession's dataTaskWithURL with Swift 2? -
while using swift 1 code worked fine:
let connectionsession = nsurlsession.sharedsession() let task = connectionsession.datataskwithurl(currenturl!, completionhandler: { (data, response , error) in ... in swift 2 getting following compiler error:
invalid conversion throwing function of type '(_, _, _) throws -> _' non-throwing function type '(nsdata?, nsurlresponse?, nserror?) -> void'
how can fix this?
to use nsjsonserialization.jsonobjectwithdata within completion handler, need catch errors:
{ var jsondata = try nsjsonserialization.jsonobjectwithdata(data!, options: .mutablecontainers) as! nsarray // stuff } catch { // handle error }
Comments
Post a Comment