composite primary key realm/swift

后端 未结 3 1709
攒了一身酷
攒了一身酷 2020-12-14 06:40

I\'m new to swift and realm. I want to make a composite primary key and when I\'m trying something like this :

class DbLocation : Object {
 dynamic var id =         


        
3条回答
  •  醉酒成梦
    2020-12-14 07:40

    For latest version of Swift and Realm, I would do something like this.

    dynamic private var compoundKey: String = ""
    
    required convenience init?(map: Map) {
      self.init()
      if let firstValue = map.JSON["firstValue"] as? String,
        let secondValue = map.JSON["secondValue"] as? Int {
        compoundKey = firstValue + "|someStringToDistinguish|" + "\(secondValue)"
      }
    }
    

提交回复
热议问题