코어 데이터에 저장된 개체가 있습니다. 다음은 값입니다.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
내가 modified
날짜가 Context
다른 경우 수정 된 객체가 managedObjectContext
에이 시간에 생각 나는 Context
의 각 attribute
을 핵심 데이터에서 유지되는 것과 비교하고 싶습니다. 그리고 attribute
이 persisted와 다른 경우 각 속성 속성에 대한 플래그를 트리거해야합니다. 일단 모든 속성이 해킹되면 컨텍스트를 저장하여 객체를 덮어 쓸 수 있습니다.
것은 내가 수동으로 확인해야합니다 생각하고 있어요 :
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 내부? 방법?
** UPDATE *
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
내가 다시 몇 객체를 얻고 로그를 볼 수 있지만 모두가 null 또는 0 I입니다 내 MOC가 비어있는 것 같아요. 개체가 mappingResult
에서 MOC
으로 어떻게 이동합니까?
감사합니다. 질문에 대한 업데이트를했는데, 내가 올바른 방향에 있는지 말해 줄 수 있니? 내가 뭔가를 잃어 버렸어 b/c 모두 0 또는 null로 올라오고있다. – user1107173
'updatedObjects'를 얻었거나 비어 있습니까? MOC가 저장되었지만 지속적 저장소까지 전파되지 않았을 수 있습니다 ... – Wain
로그를 추가했습니다. updatedObjects가 비어 있습니다. 나는 28 개의 물건을 얻고있다. SQLite Manager가 있는데 저장소에 변경 사항이 추가되지 않습니다. – user1107173