variable declaration Dictionary swift

0

I have a function to obtain the coordinates according to address.

I have to declare a variable as dictionary to transform a result into json.

var error: NSError?

let dictionary: Dictionary<NSObject, AnyObject> = NSJSONSerialization.JSONObjectWithData(geocodingResultsData!, options: NSJSONReadingOptions.MutableContainers, error: &error) as Dictionary<NSObject, AnyObject>

The error that returns to me is the following

Extra argument 'error' in call

I must say that I am guiding myself with the Google Maps document

so that piece of code got it from there so I do not know what the error can be.

    
asked by fabian 19.03.2016 в 01:31
source

1 answer

1

That method is deprecated and you should use the new form with do catch such that:

do {

    let dictionary = try NSJSONSerialization.JSONObjectWithData(geocodingResultsData!, options: NSJSONReadingOptions.MutableContainers)

} catch {

    print(error)

}

If you would like to avoid error control (I do not recommend it to you) you can do it like this:

let dictionary = try! NSJSONSerialization.JSONObjectWithData(geocodingResultsData!, options: NSJSONReadingOptions.MutableContainers)
    
answered by 19.03.2016 / 10:35
source