ios - Swift: Extra argument 'error' in call -


i'm developing first ios app using swift 2.0 , xcode beta 2. reads external json , generates list in table view data. however, i'm getting strange little error can't seem fix:

extra argument 'error' in call 

here snippet of code:

let task = session.datataskwithurl(url!, completionhandler: {data, response, error -> void in             print("task completed")              if(error != nil){                 print(error!.localizeddescription)             }              var err: nserror?              if let jsonresult = nsjsonserialization.jsonobjectwithdata(data, options: nsjsonreadingoptions.mutablecontainers, error: &err) as? nsdictionary{                  if(err != nil){                     print("json error \(err!.localizeddescription)")                 }                  if let results: nsarray = jsonresult["results"] as? nsarray{                     dispatch_async(dispatch_get_main_queue(), {                         self.tabledata = results                         self.appstableview!.reloaddata()                     })                 }             }         }) 

the error thrown @ line:

if let jsonresult = nsjsonserialization.jsonobjectwithdata(data, options: nsjsonreadingoptions.mutablecontainers, error: &err) as? nsdictionary{ 

can please tell me i'm doing wrong here?

with swift 2, signature nsjsonserialization has changed, conform new error handling system.

here's example of how use it:

do {     if let jsonresult = try nsjsonserialization.jsonobjectwithdata(data, options: []) as? nsdictionary {         print(jsonresult)     } } catch let error nserror {     print(error.localizeddescription) } 

with swift 3, name of nsjsonserialization , methods have changed, according the swift api design guidelines.

here's same example:

do {     if let jsonresult = try jsonserialization.jsonobject(with: data, options: []) as? [string:anyobject] {         print(jsonresult)     } } catch let error nserror {     print(error.localizeddescription) } 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -