ios - Issue with Swift 2 Error Handling -
i using rest json data , parse it. using nsjsonobjectwithdata, far i'm aware method used have error handler within parameters it's no longer there. in code here:
let err: nserror? let options:nsjsonreadingoptions = nsjsonreadingoptions.mutablecontainers var jsonresult = nsjsonserialization.jsonobjectwithdata(data!, options: options) as! nsdictionary;
i error says:
"call can throw, not marked 'try' , error not handled"
how go fixing error?
here correct implementation,
do { let jsondictionary = try nsjsonserialization.jsonobjectwithdata(data!, options: nsjsonreadingoptions.mutablecontainers) as! nsdictionary //use dictionary here. print("json : \(jsondictionary)") } catch { print(error) //handle error. }
Comments
Post a Comment