NSManagedObjectContextObjectsDidChangeNotification 핸들러에서 관리 객체의 속성을 변경하는 것이 핸들러를 다시 시작하지 않고 가능합니까? 서버에서 데이터를 가져오고 RestKit은 데이터를 핵심 데이터에 매핑합니다. 데이터베이스에 데이터가 도착한 후에 일부 속성을 변경해야합니다. 도움 주셔서 감사합니다.핵심 데이터 : NSManagedObjectContextObjectsDidChangeNotification의 객체 변경
편집 : 이것은 내 코드입니다. handleDidChangeNotification
방법은주기에 호출됩니다
- (void)addMyObserver
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleDidChangeNotification:)
name:NSManagedObjectContextObjectsDidChangeNotification
object:self.objectManager.managedObjectStore.mainQueueManagedObjectContext];
}
- (void)handleDidChangeNotification:(NSNotification *)notification
{
NSSet *updatedObjects = [[notification userInfo] objectForKey:NSUpdatedObjectsKey];
NSSet *deletedObjects = [[notification userInfo] objectForKey:NSDeletedObjectsKey];
NSSet *insertedObjects = [[notification userInfo] objectForKey:NSInsertedObjectsKey];
// modifiedObjects with store entity:
NSSet *modifiedObjects = [updatedObjects setByAddingObjectsFromSet:insertedObjects];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF isKindOfClass: %@", [MyStore class]];
NSSet *modifiedStoreObjects = [modifiedObjects filteredSetUsingPredicate:predicate];
if (modifiedStoreObjects.count > 0)
{
[modifiedStoreObjects enumerateObjectsUsingBlock:^(MyStore *store, BOOL *stop)
{
store.distanceValue = 1000;
}];
}
}
가져 오기에 별도 MOC 사용을 고려 했습니까? 그렇게하면이 변화를 만들기 위해 그 맥락을 관찰 할 수 있습니다. – paulbailey