So I have the following JSON, which I am using together with ObjectMapper and Realm.
{
\"result\": [
{
\"id\": 20,
\"types\": [
\"now\"
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 the
List`.
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.