DevPrep

All topics › Databases & storage

Lazy loading and Core Data

Middle PRO

Essence

Lazy loading is a pattern where data is loaded not up front but at the moment of first access. In Core Data it's implemented by faulting: the result of a fetch is a set of placeholder objects (faults) that know only their objectID; attributes are read from the store on the first property access. The same applies to relationships: author.books is a fault on a Set until you iterate it. That's why you can fetch 10,000 records and keep almost nothing in memory.

The rest of this answer, with code and interview follow-ups, is in the DevPrep app.

Read the full answer in DevPrep

Practice this before your interview

DevPrep turns these answers into one-minute challenges: what does this code print, find the bug, mock interviews. One challenge a day.

Get DevPrep on the App Store