Use NSSerialization.datawithJSON in Swift 2

后端 未结 2 1187
无人共我
无人共我 2021-01-05 17:25

Been trying to get this to work in Swift 2.0, the error says:

Type NSJSONWritingOptions cannot conform to protocol NilLiteralConvertible

2条回答
  •  灰色年华
    2021-01-05 17:44

    let options = prettyPrinted ? 
             NSJSONWritingOptions.PrettyPrinted : NSJSONWritingOptions(rawValue: 0)
    

    is the right syntax for swift 2.0

提交回复
热议问题