On 2014 Mar 31, at 00:06, Kyle Sluder <k...@ksluder.com> wrote:

> That directly contradicts the -awakeFromInsert documentation, which states 
> “This method is invoked only once in the object's lifetime.”
> 
> If you are certain you are receiving -awakeFromInsert on the *same* 
> NSManagedObject instance, you should definitely file a documentation bug.

Very good, Kyle.  I hadn’t stopped to realize the significance of that.  So, 
I’ve now re-checked my code and re-ran the test several times. Confirmed – same 
result.

Can anyone find any errors in the following?  The console output at the bottom 
shows that the same managed object (the same pointer value, even) gets 
-awakeFromInsert twice.

*** Test Code added to a method in a NSPersistentDocument implementation

// Execute this to run the test.

NSManagedObjectContext* moc = [self managedObjectContext] ;
NSEntityDescription* entity ;
entity = [NSEntityDescription entityForName:constEntityNameMessageLog
                     inManagedObjectContext:moc] ;
// MessageLog is a simple NSManagedObject subclass I don’t use very much.
MessageLog* log = [[MessageLog alloc] initWithEntity:entity
                      insertIntoManagedObjectContext:moc] ;

// Save the context
BOOL ok ;
NSError* error = nil ;
ok = [moc save:&error] ;
NSLog(@"save  ok=%hhd  error=%@", ok, error) ;

// Delete after 1 sec.
[moc performSelector:@selector(deleteObject:)
                  withObject:log
                  afterDelay:1.0] ;

// Rollback deletion after another 1 sec.
[moc performSelector:@selector(rollback)
                  withObject:nil
                  afterDelay:2.0] ;


*** Test Code, for logging, added to 'MessageLog' implementation ***

- (NSString*)essentialInfo {
    return [[NSString alloc] initWithFormat:
            @"%p oid=%@",
            self,
            [[self objectID] URIRepresentation]] ;
}

- (void)awakeFromInsert {
    NSLog(@"awakeInsert %@",
          [self essentialInfo]) ;
        [super awakeFromInsert] ;
}

- (void)awakeFromFetch {
    NSLog(@"awakeFetch %@",
          [self essentialInfo]) ;
        [super awakeFromFetch] ;
}

- (void)awakeFromSnapshotEvents:(NSSnapshotEventType)flags {
    NSLog(@"awakeSSEvt %@ flags=0x%lx",
                     [self essentialInfo],
                     (long)flags) ;
    [super awakeFromSnapshotEvents:flags ] ;
}

- (void)willTurnIntoFault {
    NSLog(@"willFault %@",
          [self essentialInfo]) ;
        [super willTurnIntoFault] ;
}


*** Console Output ***

01:54:57.451 TestApp[5149:303] awakeInsert 0x6000000b9b60 
oid=x-coredata:///MessageLog_entity/t1C13E530-8846-4F7A-9A47-B556F786BEE919
01:54:57.457 TestApp[5149:303] save  ok=1  error=(null)
01:54:59.459 TestApp[5149:303] awakeSSEvt 0x6000000b9b60 
oid=x-coredata://841930C8-B5CA-441C-B633-B9060D753DF6/MessageLog_entity/p11 
flags=0x10
01:54:59.459 TestApp[5149:303] awakeInsert 0x6000000b9b60 
oid=x-coredata://841930C8-B5CA-441C-B633-B9060D753DF6/MessageLog_entity/p11


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to