Remember, when you use lazy loading, you always have to access the object through its getter method.
for example:
@implementation LocationsViewController
{
NSFetchedResultsController *_fetchedResultsController;
}
// this is the _fetchedResultsController's getter method,
// use self.fetchedResultsController
// in other place so we can call this method everytime.
// so the lazy loading working. if we directly
// use _fetchedResultsController, can not realize lazt loading
- (NSFetchedResultsController *)fetchedResultsController
{
if (_fetchedResultsController == nil)
{
// create the fetchedResultsController
}
return _fetchedResultsController;
}
- (void)doSomething
{
// we use
[self.fetchedResultsController doSometing];
// we do not use [_fetchedResultsController doSometing];
// because we want to use last method to realize lazy loading.
}