我已保存的对象(持久)之前依然存在。可以说下面是值:RESTKit:GET对象局部比较核心数据覆盖
//Entity: employee
objectID: 1111
firstName: @"Jon"
lastName: @"D"
modified: @"10:45PM"
现在,我做一个RKManagedObjectRequestOperation *operation
请求。
我设置operation.savesToPersistentStore = NO;
并开始运作。
对象被下载,它已修改为以下几点:
//Entity: employee
objectID: 1111
firstName: @"Jonathan"
lastName: @"Doe"
modified: @"10:55PM"
//I have 15 other properties that are either Strings, NSDate, NSNumber, and BOOLs
我相信在这个时候修改的对象是在managedObjectContext
如果modified
日期是Context
不同,我想要比较Context
中的每个attribute
与核心数据中保留的那个。而如果Context
attribute
是一个比持久不同,我需要触发一个标志,每个属性属性。一旦所有的属性都被窜改,我可以通过保存上下文来覆盖对象。
我想我将不得不手动检查:
if (!([objectInCoreData valueForKey:@"firstName"] isEqualToString:[objectInContext [email protected]"firstName"]))
{
firstNameValueChange = YES; // Trigger this flag
// I have to trigger a flag for each attribute that's changed to show
// the changed value in the tableView in a different color
}
//Continue to check for each attribute, and at end overwrite persisted with Context by
[self.managedObjectContext save:&error];
问题1:我有一种感觉,有一种更好的方式来做到这一点。最佳做法是什么?
我如何可以简化检查15个不同属性的代码?
问题2:我在哪里测试,如果每个属性发生了变化?在successBlock里面? wilSave:方法?
**更新*
RKManagedObjectRequestOperation *operation = [[RKManagedObjectRequestOperation alloc]initWithRequest:request responseDescriptors:@[responseDescriptor]];
operation.managedObjectContext = self.objectManager.managedObjectStore.mainQueueManagedObjectContext;
operation.managedObjectCache = appDelegate.managedObjectStore.managedObjectCache;
operation.savesToPersistentStore = NO;
[operation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSSet *updatedObjects = [self.managedObjectContext updatedObjects];
NSLog(@"updatedObjects Count %i", updatedObjects.count);
NSArray *_updatedObjects = updatedObjects.allObjects;
NSLog(@"_updatedObjects Count %i", _updatedObjects.count);
for (int i = 0; i<_updatedObjects.count; i++)
{
Invite *invite = [_updatedObjects objectAtIndex:i];
NSDictionary *changedValues = [invite changedValues];
}
}failure:^(RKObjectRequestOperation *operation, NSError *error) {}
登录
I restkit.network:RKObjectRequestOperation.m:250 GET 'http://www.domain.com/api?lastrequest=2014-04-22T07%3A06%3A34Z' (200 OK/28 objects) [request=0.1140s mapping=0.0865s total=0.3034s]
2014-04-29 07:06:43.112 App[10627:60b] updatedObjects Count 0
2014-04-29 07:06:43.112 App[10627:60b] _updatedObjects Count 0
我可以看到,我得到几个对象后面的日志,但一切都为空或0。我猜测我的MOC是空白的。对象如何从mappingResult
到MOC
?
谢谢!我对这个问题做了更新,你能告诉我,如果我走在正确的道路上吗?我错过了什么B/C一切都是作为0或null。 – user1107173
你有没有得到'updatedObjects'或者它是空的?这可能是MOC被保存,但没有传播到持久存储... – Wain
我添加了日志。 updatedObjects是空的。我得到28个物体。我有SQLite管理器,我没有看到添加到商店的任何更改。 – user1107173