I\'m using Alamofire, Objectmapper, Realm and everything is working beside one thing: I can\'t map nested objects.
class Voting: Object, Mappable {
dyna
class ListTransform : TransformType where T:Mappable {
typealias Object = List
typealias JSON = [AnyObject]
let mapper = Mapper()
func transformFromJSON(_ value: Any?) -> Object? {
let results = List()
if let objects = mapper.mapArray(JSONObject: value) {
for object in objects {
results.append(object)
}
}
return results
}
func transformToJSON(_ value: Object?) -> JSON? {
var results = [AnyObject]()
if let value = value {
for obj in value {
let json = mapper.toJSON(obj)
results.append(json as AnyObject)
}
}
return results
}
}
Then in your model something like this.
class Parent: Object, Mappable {
dynamic var id: Int = 0
var children = List()
required convenience init?(_ map: Map) {
self.init()
}
func mapping(map: Map) {
id <- map["id"]
child <- (map["children"], ListTransform())
}
}