I'm trying to set a value and then return it using Core Data. This is what I`m doing right now :
NSManagedObjectContext *context = [(AppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
NSManagedObject *newShot = [NSEntityDescription insertNewObjectForEntityForName:@"Shots" inManagedObjectContext:context];
NSString *newName= @"test";
[newShot setValue:newName forKey:@"shotNumber"];
NSError *error = nil;
[context save:&error];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Shots" inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSArray *items = [context executeFetchRequest:fetchRequest error:&error];
[fetchRequest release];
NSLog(@"test : %@",items);
Problem is when I want to check that it stored the data correctly by returning a NSLog of the array, this is what I'm getting :
<NSManagedObject: 0x5bbbe10> (entity: Shots; id: 0x5b02b50 <x-coredata://F61F56A7-6A74-42AF-B565-6F9E091DA5F3/Shots/p14> ; data: <fault>)
Following the 2 answers, this is what I'm using :
int size = [items count];
NSLog(@"array count is %d ",size);
if (size > 0) {
NSManagedObject *mo = [items objectAtIndex:0]; // assuming that array is not empty
NSString *value = [[mo valueForKey:@"shotNumber"] stringValue];
NSLog("Value : %@",value);
}
Just having this little issue :
warning: passing argument 1 of 'NSLog' from incompatible pointer type
How can I log [mo valueForKey:@"shotNumber"]
?