Objectmapper get array of one item within JSON

微笑、不失礼 提交于 2019-12-02 04:28:24

Because Realm cannot detect assigning List properties since List property is not Objective-C type. So List properties should be declared as let, and should not be nil. You should use append/remove.../insert...method to modifying theList`.

So your code

typez <- map["types"]

doesn't work, since you assign values to the typez property directly.

The workaround is like the following:

func mapping(map: Map) {
    ...
    var typez: [String]? = nil
    typez <- map["types"]

    typez?.forEach { t in
        let obj = getType()
        obj.text = t
        self.typez.append(obj)
    }
    ...

First, store the mapped value to the local variable (it is string array). Then convert the string array to objects. Then append the objects to the List property.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!