Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem with core data lazy loading
    primarykey
    data
    text
    <p>Core Data loads objects lazily, and it is supposed to bring in any objects as soon as you try to reference them. However I have encountered a couple of problems with this scheme.</p> <p>Objective C 2.0 fast enumeration over the objects in a relationship (set) can fail (because the objects in a set are not yet loaded), and awakeFromFetch is not called until a member of the object managed by core data is touched.</p> <p>For example, if I have a relationship in a subclass of NSManagedObject such as:</p> <pre><code>@property (retain) NSSet* clips; </code></pre> <p>Immediately after fetching an instance of that object, if I try using fast enumeration such as this:</p> <pre><code>for (PClip* clip in self.clips) { // do something with the clip } </code></pre> <p>the body of the loop is never executed. In the debugger you can see that the set of clips (an instance of _NSFaultingMutableSet at run time) is initially empty. </p> <p>Or say I have a non-persistent member of the clip object that is derived from the persistent state:</p> <pre><code>@property (retain) NSString* filename </code></pre> <p>I synchronize this with the using awakeFromFetch method, but awakeFromFetch is not called until some persistent member of the object is first called, so if some code attempts to access this non-persistent value before the object is loaded, it will not yet be defined (i.e. will be nil).</p> <p>Using the setReturnsObjectsAsFaults: method on the fetch request does not seem to help. It does not appear to force fetching all of the tree of objects attached to the fetched object.</p> <p>What is the best way to ensure that objects are loaded before working with them? Why did fast enumeration fail to cause the set of objects to load?</p>
    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. 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