Database Reference
In-Depth Information
RecipesV2/PPRecipes/PPRAppDelegate.m
NSMutableDictionary *options = [NSMutableDictionary dictionary];
[options setValue:[NSNumber numberWithBool:YES]
forKey:NSMigratePersistentStoresAutomaticallyOption];
[options setValue:[NSNumber numberWithBool:YES]
forKey:NSInferMappingModelAutomaticallyOption];
NSPersistentStore *store = nil;
store = [coordinator addPersistentStoreWithType:NSSQLiteStoreType
configuration:nil
URL:storeURL
options:options
error:&error];
The first of these options, NSMigratePersistentStoresAutomaticallyOption , tells Core
Data to attempt a migration automatically if it determines that one is needed.
The second option, NSInferMappingModelAutomaticallyOption , instructs Core Data to
resolve the mapping between the persistent store and the current model. If
Core Data can figure this out, it will perform the migration.
For this migration, Core Data can easily resolve the changes that need to be
made and will be able to do an inferred migration for us. When the changes
are more severe, we need to do a heavy, manual migration, as discussed in
Section 3.4, A Heavy/Manual Migration , on page 44 .
With those changes made, we can run our application, and Core Data auto-
matically handles the migration for us and updates the persistent store to
the new model.
3.3
The Difference Between Light and Heavy Migrations
There are two types of migrations for Core Data: light migration and heavy
migration. When we are working with SQLite persistent stores, the difference
between these two types of migration is significant enough that we should
avoid doing heavy migrations if at all possible.
A light migration of a SQLite persistent store occurs within the SQLite file
itself. There are no objects loaded into memory, and therefore the memory
requirements of the migration are quite low. In addition, since the migration
is occurring within the database file, it is very fast. While the size of the
database file still affects the speed of the migration, a light migration of large
database will still be remarkably faster than a heavy migration of a small
database.
The speed and memory differences are so large that I recommend avoiding
heavy migrations at nearly any cost.
 
 
Search WWH ::




Custom Search