I have a NSManagedObject
Person Scott fetched from NSManagedObjectContext
context1. I also have the same Scott fetched from NSManagedObjectContext
context2.
I know if I fetch them from the same context, that if one is updated, the other will also be updated, but my current structure would not easily allow me to pass the same context around. I'm wondering if there is another way, something along the lines to KVO.
Can I update the Person Scott in context2 when I make a change to the Person Scott in context1?
EDIT:
Tried testing:
NSError *error = nil;
NSManagedObjectContext *context = [NSManagedObjectContext MR_context];
NSManagedObjectContext *context2 = [NSManagedObjectContext MR_context];
Boundary *boundary1 = [Boundary MR_findFirstInContext:context];
DLog(@"boundary1.name: %@", boundary1.name);
DLog(@"boundary1.managedObjectContext: %@", boundary1.managedObjectContext);
Boundary *boundary2 = (Boundary *)[context2 existingObjectWithID:boundary1.objectID error:&error];
DLog(@"boundary2.name: %@", boundary2.name);
DLog(@"boundary2.managedObjectContext: %@", boundary2.managedObjectContext);
boundary1.name = @"new name";
// Added this, does not change results
[context2 MR_observeContext:context];
DLog(@"boundary1.name: %@", boundary1.name);
DLog(@"boundary1.managedObjectContext: %@", boundary1.managedObjectContext);
DLog(@"boundary2.name: %@", boundary2.name);
DLog(@"boundary2.managedObjectContext: %@", boundary2.managedObjectContext);
results:
DEBUG | -[LoginViewController viewDidLoad] | boundary1.name: 997677
DEBUG | -[LoginViewController viewDidLoad] | boundary1.managedObjectContext: <NSManagedObjectContext: 0x1cdc6b20>
DEBUG | -[LoginViewController viewDidLoad] | boundary2.name: 997677
DEBUG | -[LoginViewController viewDidLoad] | boundary2.managedObjectContext: <NSManagedObjectContext: 0x1cdd7930>
DEBUG | -[LoginViewController viewDidLoad] | boundary1.name: new name
DEBUG | -[LoginViewController viewDidLoad] | boundary1.managedObjectContext: <NSManagedObjectContext: 0x1cdc6b20>
DEBUG | -[LoginViewController viewDidLoad] | boundary2.name: 997677
DEBUG | -[LoginViewController viewDidLoad] | boundary2.managedObjectContext: <NSManagedObjectContext: 0x1cdd7930>
The change to boundary1
's name does not persist into boundary2
's name.