How to check whether data is stored in core data ?

Posted by Warrior on Stack Overflow See other posts from Stack Overflow or by Warrior
Published on 2010-05-04T13:49:58Z Indexed on 2010/05/04 13:58 UTC
Read the original article Hit count: 145

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about coredata