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

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -