You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I need a little guidance with mapping nested objects. I managed to use ObjectMapper with built in types perfect. But how do I map nested custom objects?
Given something like this:
classA{letb:Bletc:[C]}
As I said I managed to map B and C alone. But how do I map it from inside A? Do I need to write a custom transform? Or do I need to make B and C conform to some protocol? I am guessing it is quite simple but I just can't get my head around it.
The text was updated successfully, but these errors were encountered:
Here is an example from the tests included in the framework. The key is that any nested objects also need to conform to the Mappable protocol. Also, by default ObjectMapper does not support immutable types (let) as member variables.
Hope this helps
class Plan: Mappable {
var primaryTask: Task?
var tasks: [Task]?
required init?(_ map: Map) {
mapping(map)
}
func mapping(map: Map) {
tasks <- map["tasks"]
}
}
class Task: Mappable {
var taskId: Int?
var percentage: Double?
init() {}
required init?(_ map: Map) {
mapping(map)
}
func mapping(map: Map) {
taskId <- map["taskId"]
percentage <- map["percentage"]
}
}
I need a little guidance with mapping nested objects. I managed to use ObjectMapper with built in types perfect. But how do I map nested custom objects?
Given something like this:
As I said I managed to map B and C alone. But how do I map it from inside A? Do I need to write a custom transform? Or do I need to make B and C conform to some protocol? I am guessing it is quite simple but I just can't get my head around it.
The text was updated successfully, but these errors were encountered: