How to map in Realm List an array of integers from JSON with ObjectMapper

899 Views Asked by At

I have JSON:

{ 
"id": 5,
"name": "Name of object",
"filter_ids": [ 10, 15, 20 ] 
}

I use ObjectMapper for parse JSON to Realm Object.

I have vars in object:

dynamic var identifier: Int = 0 
dynamic var name: String = "" 
var filter_ids = List<Int>() 

How to map filter_ids var?

func mapping(map: Map)  {
     identifier <- map["id"]
     name <- map["name"]
     filter_ids <- map["filter_ids"] //?????? not work
}
1

There are 1 best solutions below

0
On

I used cocoaPod (carthage works too) ObjectMapperAdditions

filter_ids <- (map["filter_ids"], RealmTypeCastTransform())

It works for Int, String, Bool arrays.

Duplicated discussion