Database Reference
In-Depth Information
if (!store) {
ALog(@ "Error adding persistent store to coordinator %@\n%@" ,
[error localizedDescription], [error userInfo]);
NSString *msg = nil;
msg = [NSString stringWithFormat:@ "The recipes database %@%@%@\n%@\n%@" ,
@ "is either corrupt or was created by a newer " ,
@ "version of Grokking Recipes. Please contact " ,
@ "support to assist with this error." ,
[error localizedDescription], [error userInfo]];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@ "Error"
message:msg
delegate:self
cancelButtonTitle:@ "Quit"
otherButtonTitles:nil];
[alertView show];
return ;
}
This is the new creation of the persistent store inside the -initializeCoreDataStack
method. Once we have initialized our persistent store coordinator, we kick
off a background process to add the NSPersistentStore to the NSPersistentStoreCoordi-
nator . If there is an error here, we need to present it to the user and halt the
application. We do this with a UIAlertView showing the error to the user, and
then the delegate of the UIAlertView forces the application to quit. The resulting
error message is shown in Figure 7, Version error on iOS , on page 40 . In a
production application, we would perhaps offer the user the option to reset
the data as opposed to exiting. Note that we also have an ALog before the
UIAlertView . When we are developing this application, we want to make very
sure that a developer-level error fires here to ideally avoid the risk of the user
ever encountering it.
3.2
A Simple Migration
To demonstrate a simple migration, let's add the ability to attribute recipes
to authors. To begin the versioning, the first thing we need to do is create a
new managed object model (MOM) based on the first one. To do that, we need
to select the existing model in Xcode and then choose Design > Data Model
> Add Model Version.
Creating a Versioned Data Model
This is the first time we have added a model version, so Xcode is going to
create a new bundle for us called PPRecipes.xcdatamodeld and put the original
MOM inside the bundle along with a new copy of the original MOM. To make
things clearer in the example project, I renamed these MOM objects to
 
 
Search WWH ::




Custom Search