1

I am using https://github.com/newlix/PRSync/ to sync RLMObjects to Parse backend and vice versa. Let's say I need to push a RLMObject, I use the following function from the PRSync.swift.

public func pushObjectEventually<T:RLMObject where T:Syncable>(obj:T) {
  let pfo = PFObject(className: Constants.SaveActionClassName)
  pfo["parseClassName"] = T.className()
  for prop in properties(T.self) {
    if prop != "objectId" {
      pfo[prop] = obj[prop]
    }
  }
  pfo["timestamp"] = NSDate().timeIntervalSince1970
  pfo.saveEventually { success, error in
    if error != nil {
      println(error.localizedDescription)
    }
  }

If I have a RLMObject that does not hold a to-many relationship with another object (i.e. does not contain and RLMArray type) everything works well. However, for RLMObjects that have RLMArray types (e.g. Client has to-many relationship with Entry), the function crashes-

 'PFObject values may not have class: RLMArray' 

Could someone from Realm advise me on the best approach for mapping my RLMArray entries containing Entry objects (having to-many relationship) in the Client RLMObject, when I want to convert the Client object to a PFObject and save it to Parse backend? I am sorry, but I did not find a lot of literature explaining this properly.

 class Client: RLMObject, Syncable {

    dynamic var objectId:String = ""
    dynamic var identifier:String = NSUUID().UUIDString
    dynamic var timestamp:Double = NSDate().timeIntervalSince1970
    dynamic var address = Address()
    dynamic var notes: String = ""
    dynamic var phone: String = ""
    dynamic var fax: String = ""
    dynamic var email: String = ""
    dynamic var website: String = ""
    dynamic var entries = RLMArray (objectClassName: Entry.className())

    override class func primaryKey() -> String! {
        return "identifier"
    }
}
Dharmesh Dhorajiya
  • 3,976
  • 9
  • 30
  • 39
Subzero
  • 841
  • 6
  • 20
  • It seems like Parse wants that RLMArray to be an NSArray instead of an RLMArray... have you tried transforming the array and setting that as the property on the PFObject? – segiddins Feb 16 '15 at 05:35
  • I spoke with newlix separately and got to know that he does not intend prsync to handle relations in RLMObject, instead he advised me to use a non-relational approach. He also mentioned (too bad) that he is not going to maintain the library anymore "because it's too hard to test against a Parse backend efficiently and is lack of automatically backup tools." – Subzero Feb 21 '15 at 18:40

0 Answers0