Database Reference
In-Depth Information
Figure 3—Creating a new data model
Loading the Data Model
Once we have created the source file for the data model, we need to instantiate
it within our application. In the Xcode sample projects, this is generally done
in its own method in the application's AppDelegate . However, this process is
unnecessary and tends to add to code bloat in the AppDelegate . My preference
is to construct the entire Core Data stack in a single method because it is a
single action from the perspective of the application. Further, I prefer to kick
off the initialization of the Core Data stack as soon as the application
launches so that it is available, in some form, immediately. Therefore, in our
sample application, we have a method named -initializeCoreDataStack that starts
off with constructing the data model.
RecipesV1/PPRecipes/PPRAppDelegate.m
- ( void )initializeCoreDataStack
{
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@ "PPRecipes"
withExtension:@ "momd" ];
ZAssert(modelURL, @ "Failed to find model URL" );
NSManagedObjectModel *mom = nil;
mom = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
ZAssert(mom, @ "Failed to initialize model" );
 
 
 
Search WWH ::




Custom Search