开发者

Core Data fetch persistance

开发者 https://www.devze.com 2023-04-05 10:13 出处:网络
I am wondering if someone could clarify the following from Apples Core Data documentation: Changes are not reflected until after the controller’s managed object

I am wondering if someone could clarify the following from Apples Core Data documentation:

Changes are not reflected until after the controller’s managed object context has received a processPendingChanges message. Therefore, if you change the value of a managed object’s attribute so that its location in a fetched results controller’s results set would change, its index as reported by the controller would typically not change until the end of the current event cycle (when processPendingChanges is invoked). For example, the following code fragment would log “same”:

NSFetchedResultsController *frc = <#A fetched results controller#>;
NSManagedObject *managedObject = <#A managed object in frc's fetchedObjects array#>;
NSIndexPath *beforeIndexPath = [frc indexPathForObject:managedObject];
[managedObject setSortKeyAttribute:
                  <#A new value that changes managedObject's position in frc's fetchedObjects array#>;
NSIndexPath *afterIndexPath = [frc indexPathForObject:managedObject];
if ([beforeIndexPath compare:afterIndexPath] == NSOrderedSame) {
    NSLog(@"same");
}

What exactly does "would typically not change until the end of the current event cycle" mean? I have this situation in my code but am not reall开发者_C百科y sure if I can 100% rely on my indexes staying the same until I explicitely preform a save on my managed object context. Could the above code be modified, without performing a save to the context, such that it doesn't log "same"?


not really sure if I can 100% rely on my indexes staying the same until I explicitely preform a save on my managed object context.

I wouldn't. The "current event cycle" is the current iteration of the run loop.

0

精彩评论

暂无评论...
验证码 换一张
取 消