我想我想通了。我创建了一个方法,将对象添加到 Core Data 并为未提供的任何数据写入 nil 值。例如:
+(BOOL) addActivity:(NSNumber *)identifier item_id:(NSNumber *)item_id {
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = appDelegate.managedObjectContext;
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Activity" inManagedObjectContext:context];
Activity *a = [NSEntityDescription insertNewObjectForEntityForName:[entity name] inManagedObjectContext:context];
[a setValue:identifier forKey:@"id"];
[a setValue:item_id forKey:@"item_id"];
// Save the context.
NSError *error = nil;
if (![context save:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
return NO;
} else {
return YES;
}
return NO;
}
显然 SPDiffer 不喜欢这样,因为它不断抛出错误,例如:
transform diff for a ghost member (ghost <SPGhost: 0x7fba9617dae0>, memberData {
<data>
}) that doesn't exist (item_id): {
o = "+";
v = 0;
}
当 item_id 确实存在时,除了它写入了 nil 值,因此 SPDiffer 无法分辨类型。我在我的代码中添加了一些 if 语句,所以我不写 nil 值而只是忽略该字段。
if (item_id) {
[a setValue:item_id forKey:@"item_id"];
}
I hope this makes sense and helps someone else out.