我是 obj-c 的新手,在这里编写一个方便的例程来从核心数据存储中获取实体。XCode 警告我我缺少返回值。为什么?
- (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;
}
警告附加到 executeFetchRequest 行。