Search code examples
objective-ccocoacore-datansfetchrequest

Does NSSet *children = [parent children]; perform a fetch request?


Is NSSet *children = [parent children]; causing core data to perform a fetch, returning all instances of the child entity relationship?

Same in IB: Does a Model Key Path with a nested relationship perform a fetch request?


Solution

  • It returns a Core Data internal 'faulting' set object that works like a set. When you access an item in the set, it will go to your persistent store for the data on first access. This is effectively indexed, so it will be faster than many fetch requests, and sometimes the relationship fault may have already fired, so it wouldn't go to the store at all.

    Use the com.apple.CoreData.SQLDebug environment variable to figure out just what's going on under the hood and fine tune performance. Set it to 1 in your scheme.