Reputation: 161
I am trying to code a method that performs a fetch based on the ID(NSInteger value) I have passed in. I can form a fetch of everything, but when I add the predicate, the program crashes. Have I done the predicate wrong.
-(BOOL)finding:(NSInteger)theID
{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"self == %i",theID];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc]init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Course" inManagedObjectContext:_cdStack.managedObjectContext];
[fetchRequest setEntity:entity];
[fetchRequest setHavingPredicate:predicate];
NSError *error = nil;
NSArray *fetchedObjects = [_cdStack.managedObjectContext executeFetchRequest:fetchRequest error:&error];
}
Upvotes: 0
Views: 120
Reputation: 76
This question is pretty old, but I just ran into the same error mentioned in the followup discussion. So just in case if someone else ends up with the same issue, the problem is using [fetchRequest setHavingPredicate: predicate];
instead of [fetchRequest setPredicate: predicate];
.
Upvotes: 1