Skip to content
This repository has been archived by the owner on Jun 5, 2018. It is now read-only.

NSManagedObjectContextDidChangeNotification not being called in gh-unit #168

Open
luhui opened this issue Jan 7, 2015 · 0 comments
Open

Comments

@luhui
Copy link

luhui commented Jan 7, 2015

I just write a test case for core data observer, but I found the NSManagedObjectContextDidChangeNotification not called with update the value, but It is called in my application with the same code.
My test code below:

    [MagicalRecord setupAutoMigratingCoreDataStack];
    [[NSNotificationCenter defaultCenter] addObserverForName:NSManagedObjectContextObjectsDidChangeNotification object:[NSManagedObjectContext MR_defaultContext] queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
        NSLog(@"did change:%@", note);
    }];
    [MagicalRecord saveWithBlockAndWait:^(NSManagedObjectContext *localContext) {
        Babies *b = [Babies MR_createInContext:localContext];
        b.nickName = @"aloha";
        b.objectId = @"1";
    }];
    Babies *b = [Babies MR_findFirstByAttribute:BaseEntityAttributes.objectId withValue:@"1" inContext:[NSManagedObjectContext MR_defaultContext]];
    NSLog(@"b:%@ context:%@", b.nickName, [[b managedObjectContext] MR_parentChain]);
    [MagicalRecord saveWithBlockAndWait:^(NSManagedObjectContext *localContext) {
        Babies *e = [b MR_inContext:localContext];
        e.nickName = @"cool";
    }];
    NSLog(@"b:%@", b.nickName);

dependence with MagicalReocrd

The first 'saveWithBlockAndWait:' will insert an entity, the NSManagedObjectContextDidChangeNotification is called.

The second saveWithBlockAndWait: will update the entity has inserted above, and NSManagedObjectContextDidChangeNotification is not being called, but the entity has already refresh.

Any idea to resolve this problem?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant