Thursday, February 7, 2013

Core data lazy loading

Apple's explanation on Core data lazy loading.

When you execute a fetch, Core Data fetches just instances of the entity you specify. In some situations, the destination of a relationship is represented by a fault. Core Data automatically resolves (fires) the fault when you access data in the fault. This lazy loading of the related objects is much better for memory use, and much faster for fetching objects related to rarely used (or very large) objects. It can also, however, lead to a situation where Core Data executes separate fetch requests for a number of individual objects, which incurs a comparatively high overhead.

Source - https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreData/Articles/cdPerformance.html

How to see raw sql in core data execution

In XCode, go to scheme list and select edit scheme. Pick 'Run' scheme and select arguments.
In 'Arguments passed on launch' add the following “-com.apple.CoreData.SQLDebug 1”.
Now when you run the app you will see the sql execution status in the output window.

Source - http://www.raywenderlich.com/934/core-data-on-ios-5-tutorial-getting-started