Alamofire, Objectmapper, Realm: Nested Objects

前端 未结 4 1288
梦谈多话
梦谈多话 2021-01-13 05:16

I\'m using Alamofire, Objectmapper, Realm and everything is working beside one thing: I can\'t map nested objects.

class Voting: Object, Mappable {

    dyna         


        
4条回答
  •  一生所求
    2021-01-13 05:38

    You can extend ObjectMapper for Realm.List type with a operator function like as:

    public func <- (left: List, right: Map) {
      if right.mappingType == MappingType.FromJSON {
        if let value = right.currentValue {
          left.removeAll()
          if let json = value as? [[String : AnyObject]] {
            let objs = RealmS().add(T.self, json: json)
            left.appendContentsOf(objs)
          }
        }
      }
    }
    

    Try yourself.

    ObjectMappper + Realm List type

提交回复
热议问题