如何更有效地将我的服务器数据(字典数组)同步到我的核心数据?
我的想法如下,但想知道是否有其他更合适的方式或第三方库可用于更新我的核心数据?
for coreItem in coreData {
coreItem.isSynced = false
for serverItem in serverData {
let predicate = NSPredicate(format: "%s == %s", coreItem.ID , serverItem.ID )
fetchRequest.predicate = predicate
var error: NSError?
let fetchedResults = managedObjectContext!.executeFetchRequest(fetchRequest, error: &error) as? [item]
if let results = fetchedResults {
coreItem.isSynced = true
if (results.count > 0) {
//TODO --> item exists in core data. proceed to update all attributes for this item.
}
else {
//TODO --> item does not exist in core data. proceed to add item to core data.
}
}
}
if (!coreItem.isSynced) {
//TODO --> item is not found in server. proceed to delete data.
}
}