I’m crashing with this message :
‘NSInvalidArgumentException’, reason: ‘keypath name not found in entity
Obvisouly I’m not querying my entity correctly .
//fetching Data
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSManagedObjectContext *context = [(AppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Viewer" inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSString *attributeName = @"dF";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name like %@",attributeName];
[fetchRequest setPredicate:predicate];
NSLog(@"predicate : %@",predicate);
NSError *error;
NSArray *items = [context executeFetchRequest:fetchRequest error:&error];
NSLog(@"items : %@",items);
[fetchRequest release];
//end of fetch
And here is my data Model:

I want to return the value of "dF", shouldn’t call it like this ? :
NSString *attributeName = @"dF";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name like %@",attributeName];
If you want to get value from your
dFproperty, you have to fetch an array ofNSManagedObjectsand then use[fetchedManagedObject valueForKey:@"dF"];to get your value.Predicates are used to get array of
NSManagedObjectsthat satisfy your criteria. E.g. if yourdFis a number, you can create predicate like “dF > 100“, then your fetch request will return an array withNSManagedObjectsthat will have dF values that > 100. But if you want to get just values, you don’t need any predicate.