I am watching/doing the iTunes U Stanford iPhone course. (provided for free!). I am on the paparazzi program trying to figure out Core Data.
Below is how I save data into coreData, how do I verify this information actually got saved?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
FlickrFetcher *ff = [FlickrFetcher sharedInstance];
if (![ff databaseExists])
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"FakeData" ofType:@"plist"];
NSArray *data = [NSArray arrayWithContentsOfFile: path];
NSManagedObjectContext *managedObjectContext = [ff managedObjectContext];
NSError *error = nil;
for (NSDictionary *row in data)
{
Person *person = (Person *)[NSEntityDescription insertNewObjectForEntityForName:@"Person" inManagedObjectContext:managedObjectContext];
Photo *photo = (Photo *)[NSEntityDescription insertNewObjectForEntityForName:@"Photo" inManagedObjectContext:managedObjectContext];
photo.name = [row objectForKey:@"name"];
photo.url = [row objectForKey:@"path"];
person.name = [row objectForKey:@"user"];
[person addPhotosObject:photo];
}
[managedObjectContext save:&error];
}
In your code you would check whether
errorisnilafter you have sent thesave:message to the managedObjectContext, or alternatively, whether the return value of that expression isYES. If that’s the case, it means there were no errors while saving your changes in the context.If you just want to check by hand (e.g. after already running the code previously), you can of course simply open the SQLite database in some browser and check the data is there. SQLite Manager extension for Firefox is a nice tool for that.