After creating a new version of your data model, and adding the relevant code to handle lightweight migration, to actually get your code to run ensure that you do a clean all targets otherwise you get merge model errors!
After creating a new version of your data model, and adding the relevant code to handle lightweight migration, to actually get your code to run ensure that you do a clean all targets otherwise you get merge model errors!
I’ve used the following code to retrieve an entity from Core Data, so that the result returns the entity object rather than a Dictionary
-(Target *) currentTargetInContext:(NSManagedObjectContext *)context {
Target *match;
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName: @"Target" inManagedObjectContext:context];
[request setEntity:entity];
[request setResultType:NSManagedObjectResultType];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"Achieved == 0 "];
[request setPredicate:predicate];
NSError *error;
NSArray *objects = [context executeFetchRequest:request error:&error];
match = nil;
if (objects == nil)
{
// handle the error
}
else
{
if ([objects count] > 0)
{
match = (Target *)[objects objectAtIndex:0];
}
}
[request release];
return match;
}
This Firefox add-on allows you to view the data you are running against while using the iPhone simulator. Your sqlite files can be found in the following folder
/Users/”user name”/Library/Application Support/iPhone Simulator/User/Applications/”application guid”/Documents

This is a great tool for view the data you’ve created within your apps, but I would suggest that is best to define your data model via Xcode
When you alter your underlying data model the iPhone simulator will not be able to load your app as the cached version of the database doesn’t match the new one. The easiest way to resolve the problem is to run the simulator, click and hold your app and remove it like you would remove an app from your actual phone.
Once you’ve created your data model within Xcode, you may need to generate the classes so that you can use and reference them in your main project. To do this open the data model, select File/New File… from the Xcode menu system, this will display the following screen…

New File screen with Managed Object Class selected