I’m new to obj-c, here writing a convenience routine to fetch entities from a Core Data store. XCode is warning me that I’m missing a return value. Why?
- (NSArray *)findEntities:(NSString *)entityName byField:(NSString *)fieldName andValue:(id)fieldValue
{
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:entityName];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K == %@", fieldName, fieldValue];
[fetchRequest setPredicate:predicate];
NSError *error;
NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];
if (error) {
NSLog(@"LWStore: findEntities error: %@", [error localizedDescription]);
}
return fetchedObjects;
}
The warning is attached to the executeFetchRequest line.
Pasting this code into a new project gives me no errors, which is understandable since it looks like you’d always return a value. Try cleaning, analyzing or anything that will cause Xcode to check for errors anew and see if the error goes away.