Here's an example of lazy loading from the Core Data template:
- (NSManagedObjectModel *)managedObjectModel
{
if (managedObjectModel != nil) {
return managedObjectModel;
}
managedObjectModel = [[NSManagedObjectModel mergedModelFromBundles:nil] retain];
return managedObjectModel;
}
The first time the managedObjectModel
is asked for, it is created by the code. Any time after that, it already exists (!= nil
) and is just returned. That's one example of lazy loading. There are other kinds, such as lazy loading of NIB files (loading them into memory only when they're needed).