Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I do not have that book, but I'll try to help...</p> <p>However, it does not look wrong to me. It looks like exactly what I would expect (assuming aPerson lives in a different context when setCurrentPerson is called). I'll try to walk through the code you posted. Maybe I can some how determine what your question is, and somehow provide an answer in the process. My comments are included in the code as, well, comments.</p> <pre><code>- (void)setCurrentPerson:(AWPerson *)aPerson { if( !aPerson ) { // The aPerson object we were given is nil, so get one in the // current editingContext. aPerson = [AWPerson randomPersonInManagedObjectContext:self.editingContext]; } else if( [aPerson managedObjectContext] != self.editingContext ) { // The aPerson object does not live in editingContext. However, apparently // we want to make sure it lives in the editingContext. Remember, each managed // that has been saved will have a permanent object-id. Any context can use // the object-id to fetch an object into its own ManagedObjectContext. self.title = @"Edit person"; aPerson = (id)[self.editingContext objectWithID:[aPerson objectID]]; // Now, aPerson will point to an object that lives in the MOC editingContext. // However, if it was not previously registered in that MOC, it will be returned // as a fault. This does not mean the object is not there, but this MOC has // not loaded its data. As soon as you cal a method that needs the data, // it will be faulted into memory. // One way, is to access any of its properties. NSLog(@"firstName = %@", [aPerson valueForKey:@"firstName"]); // You can query an object to see if it is a fault. NO means it's // not a fault, and the properties should all be in memory. YES, does not mean // the data is NOT in memory though... it could be in a cache... // You can manually fault the object into memory, but I would // suggest you read all the documentation before using this, because it has // side effects. Consider... if ([aPerson isFault]) { [self.editingContext refreshObject:aPerson mergeChanges:YES]; } // NOTE: In general, you just want the object management system itself // to manage faults. However, if you really want to see that your objects // are what they are supposed to be, you can do any of this to examine them. } [...] } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload