0
let data = json.data(using: String.Encoding.utf8)!
let wrapper = JSONSerialization.JSONObjectWithData(data, options:nil, error:nil) as NSDictionary

Error is thrown on this line

let wrapper = JSONSerialization.JSONObjectWithData(data, options:nil, error:nil) as NSDictionary
EmilioPelaez
  • 18,758
  • 6
  • 46
  • 50

1 Answers1

1

what do i do?

Remove the extra argument. The Swift version of the method is declared like this:

class func jsonObject(with data: Data, options opt: JSONSerialization.ReadingOptions = []) throws -> Any

As you can see, it throws an error instead of taking an error parameter. There's even a sidebar in the documentation labeled Handling Errors in Swift: that explains a bit about how to use this method with try/catch to handle errors, and there's a link to more information on the topic.

Caleb
  • 124,013
  • 19
  • 183
  • 272