markdb314 markdb314 - 1 year ago 78
iOS Question

How to pass no options to NSJSONSerialization.JSONObjectWithData in Swift

I want to pass no options when deserializing JSON in Swift (2.0). I originally tried:

NSJSONSerialization.JSONObjectWithData(data, options: nil)

But that doesn't compile, I get the error:

Type NSJSONReadingOptions does not conform to protocol NilLiteralConvertible

The enum NSJSONReadingOptions doesn't have any 'None' option, so what do I do if I don't want of any of these options?

Answer Source

In swift 2 you should use the empty array [] to indicate no options:

NSJSONSerialization.JSONObjectWithData(data, options: [])
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download