• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Removing object as observer in -willTurnIntoFault
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Removing object as observer in -willTurnIntoFault


  • Subject: Re: Removing object as observer in -willTurnIntoFault
  • From: Jerry Krinock <email@hidden>
  • Date: Mon, 31 Mar 2014 02:14:55 -0700

On 2014 Mar 31, at 00:06, Kyle Sluder <email@hidden> 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 (email@hidden)

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:

This email sent to email@hidden


References: 
 >Removing object as observer in -willTurnIntoFault (From: Jerry Krinock <email@hidden>)
 >Re: Removing object as observer in -willTurnIntoFault (From: Dado Colussi <email@hidden>)
 >Re: Removing object as observer in -willTurnIntoFault (From: Jerry Krinock <email@hidden>)
 >Re: Removing object as observer in -willTurnIntoFault (From: Kyle Sluder <email@hidden>)

  • Prev by Date: Re: Removing object as observer in -willTurnIntoFault
  • Next by Date: Re: Removing object as observer in -willTurnIntoFault
  • Previous by thread: Re: Removing object as observer in -willTurnIntoFault
  • Next by thread: Re: Removing object as observer in -willTurnIntoFault
  • Index(es):
    • Date
    • Thread