0
我正在使用iOS的Realm框架,並試圖從解析查詢中創建數組中的多個對象,但保持檢查沒有任何重複在當地的領域。創建或更新在iOS中不工作的領域框架的功能
let lastSyncDate = NSUserDefaults.standardUserDefaults().objectForKey("com.fridge.sync.last") as NSDate
let query = PFQuery(className: "Category", predicate: NSPredicate(format: "updatedAt > %@", lastSyncDate))
query.findObjectsInBackgroundWithBlock { (results, error) -> Void in
if error != nil {
return
}
if results.isEmpty {
return
}
let realm = RLMRealm.defaultRealm()
/*realm.transactionWithBlock({() -> Void in
for remoteCategory in results as [PFObject] {
let category = Category()
category.name = remoteCategory["name"] as String
category.image = NSData()
realm.addObject(category)
}
})*/
/*realm.beginWriteTransaction()
for remoteCategory in results as [PFObject] {
let category = Category()
category.name = remoteCategory["name"] as String
category.image = NSData()
realm.addObject(category)
}
realm.commitWriteTransaction()*/
}
我還使用了creatorupdate版本,但它仍然無法保存任何對象,由於某種原因,我不能調試什麼的境界裏面的代碼heppening的東西。
類型模型是這樣的:
class Category: RLMObject {
dynamic var categoryId: String = ""
dynamic var name: String = ""
dynamic var image: NSData = NSData()
var stores: [Store] {
return linkingObjectsOfClass(Store.className(), forProperty: "category") as [Store]
}
override class func primaryKey() -> String {
return "categoryId"
}
}
什麼可能會錯誤的任何想法是極大的讚賞。 在此先感謝
好吧,它的工作如你所說,非常感謝。從源頭上構建你的意思是什麼? – 2014-11-24 21:15:23
Realm是開源的,如果您自己構建框架,則可以更輕鬆地調試Realm代碼。 Realm的來源可以在這裏找到:https://github.com/realm/realm-cocoa – Ari 2014-11-24 21:17:18