我正在使用https://github.com/newlix/PRSync/同步RLMObjects
到 Parse 后端,反之亦然。假设我需要推送一个RLMObject
,我使用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)
}
}
如果我有一个RLMObject
与另一个对象不存在多对多关系的对象(即不包含和RLMArray
类型),则一切正常。但是,对于RLMObjects
具有RLMArray
类型(例如,客户端与条目具有多对多关系),函数会崩溃-
'PFObject values may not have class: RLMArray'
当我想将对象转换为 a并将其保存到 Parse 后端时,Realm 的人可以建议我映射包含对象(具有多对多关系)的RLMArray
条目的最佳方法吗?很抱歉,但我没有找到很多正确解释这一点的文献。Entry
Client
RLMObject
Client
PFObject
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"
}
}