NSJSONWritingOptions解释

时间:2015-11-17 22:34:19

标签: swift

使用


NSJSONSerialization.dataWithJSONObject(array, options: NSJSONWritingOptions(rawValue:2))

你能告诉med rawValue的用途是什么吗?

1 个答案:

答案 0 :(得分:6)

rawValue位来自OptionSetTypeNSJSONWritingOptions继承了该位。

最有可能你应该完全避免使用标准的Swift枚举语法,它提供了一个很好的短常量名称:

NSJSONSerialization.dataWithJSONObject(array, options: .PrettyPrinted)

修改

要指定没有选项或多个选项,您可以使用恢复为rawValue语法并自己计算值,就像在C中一样,但更简单的选项是下面的数组样式语法:

不指定选项:

NSJSONSerialization.dataWithJSONObject(array, options: [])

结合多个选项:

NSJSONSerialization.JSONObjectWithData(data, options: [.MutableContainers, .MutableLeaves])