How to check whether data is stored in core data ?
- by Warrior
i am new to iphone development. I am trying to save a static values in to core data database.I want to check whether the data is stored to the database, i am not able to retrieve the data from the database, so i want to check myself whether i made mistake in retrieving the data or in storing the data itself.
NSManagedObjectContext *context = [self managedObjectContext];
NSManagedObject *event = [NSEntityDescription insertNewObjectForEntityForName:@"Event" inManagedObjectContext:context];
[event setValue:fname forKey:@"firstname"];
[event setValue:lname forKey:@"lastname"];
i put the above code in the submit button of my formclass. when i restart the app i fetch the data in main view class using this code
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Event"
inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];
NSError *error;
NSArray *items = [self.managedObjectContext
executeFetchRequest:fetchRequest error:&error];
for (Event *info in items) {
NSLog(@"the selected value is : %@", [info valueForKey:@"firstname"]);
}
[fetchRequest release];
i dont know where i am going wrong.Please help me out.Thanks.