Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You want:</p> <pre><code>-(NSManagedObject *)existingObjectWithID:(NSManagedObjectID *)objectID error:(NSError **)error </code></pre> <p>Fetches the object from the store that has that ID, or nil if it doesn't exist.</p> <p>(Be aware: there are two methods on NSManagedObjectContext with similar-seeming names that tripped me up. To help keep them straight, here's what the other two do:</p> <pre><code>-(NSManagedObject *)objectWithID:(NSManagedObjectID *)objectID </code></pre> <p>...will create a fault object with the provided objectID, <strong>whether or not</strong> such an object actually exists in the store. If it doesn't exist, anything that fires the fault will fail unless you insert the object first with NSManagedObjectContext's <code>insertObject:</code>. The only use I've found for this is copying objects from store to store while preserving ObjectIDs.</p> <pre><code>-(NSManagedObject *)objectRegisteredForID:(NSManagedObjectID *)objectID </code></pre> <p>...will return the object that has that ID, <strong>if</strong> it has been fetched from the store by this managedObjectContext. If anyone knows what this method is useful for, please comment.)</p> <p>[eta.: Another important difference between the first method and the other two is that <code>existingObjectWithID:error:</code> never returns a fault; it always fetches the whole object for you. If you're trying to avoid that (e.g. working with an expensive-to-fetch object with a big blob property), you have to be clever with <code>objectWithID:</code> or <code>objectRegisteredForID:</code>, which don't fire faults; or use a properly configured fetch request.]</p>
 

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