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"
}
}