我尽量不设置仅在JSON中存在的值。我想做这样的事情:
if (map["doc.type"] != nil) {
picturePath <- map["doc.type"]
}我正在使用这个ObjectMapper框架:https://github.com/Hearst-DD/ObjectMapper
发布于 2016-05-13 21:17:27
<-是返回可选类型的映射运算符。如果未提供密钥"doc.type“,则picturePath为nil。
如果您想根据不同的键完全填充picturePath,最好的方法可能是使用helpers变量,然后根据它们分配picturePath。
例如:
var optionalPicturePath: String? = map["doc.type"]
if optionalPicturePath != nil {
picturePath = optionalPicturePath
}https://stackoverflow.com/questions/34727438
复制相似问题