In my Realm object model I have an object called "Event". Each Event has a list of EventLocatons. I am trying to map these object from json, but the list of EventLocations is always empty. The objects look like this (simplified for clarity):
class Event: Object, Mappable {
override class func primaryKey() -> String? {
return "id"
}
dynamic var id = ""
var eventLocations:List<EventLocation> = List<EventLocation>()
func mapping(map: Map) {
id <- map["id"]
eventLocations <- map["eventLocations"]
}
}
class EventLocation: Object, Mappable {
override class func primaryKey() -> String? {
return "id"
}
dynamic var id: String = ""
dynamic var name: String = ""
required convenience init?(_ map: Map) {
self.init()
}
func mapping(map: Map) {
id <- map["id"]
name <- map["name"]
}
}
The json, that I have is an array of Event objects. It comes from an Alamofire response and I map it like that:
var events = Mapper<Event>().mapArray(json!)
The json looks like this:
[
{
"id" : "21dedd6d",
"eventLocations" : [
{
"name" : "hh",
"id" : "e18df48a",
},
{
"name" : "tt",
"fileId" : "be6116e",
}
]
},
{
"id" : "e694c885",
"eventLocations" : [
{
"name" : "hh",
"id" : "e18df48a",
},
{
"name" : "tt",
"fileId" : "be6116e",
}
]
}
]
Does anyone know how can I map a list of custom objects using the Mappable protocol. Whay is the "eventLocations" list always empty?