我正在从CoreData我期望的地方1 result或nil.
目前我将 fetch 设置为 aNSArray并且我尝试将其提取到一个IconRoutine*对象中,但[context executeFetchRequest:fetchIcon error:&error];需要提取到一个数组中,因此在我尝试这样做时会导致崩溃。
我想我想知道我是否可以以另一种方式获取 aentity object以便我不需要if ( [Icon count] !=0 )检查 anil并且我可以返回获取的任何内容并nil entity在另一种方法中处理。
或者也许只是一种更有效的方式(如果有的话)来处理您期望的结果1或nil.
- (IconRoutine *) getIconRoutine {
NSFetchRequest *fetchIcon = [[NSFetchRequest alloc] init];
NSEntityDescription *entityItem = [NSEntityDescription entityForName:@"IconRoutine" inManagedObjectContext:context];
[fetchIcon setEntity:entityItem];
[fetchIcon setRelationshipKeyPathsForPrefetching:[NSArray arrayWithObjects:@"User",@"Routine", nil]];
[fetchIcon setPredicate:[NSPredicate predicateWithFormat:@"(routine.routineName == %@) AND (user.email LIKE %@) AND (author LIKE %@)",_routineNameInput.text,_appDelegate.currentUser,_routineAuthor]];
NSError *error = nil;
NSArray* Icon = [context executeFetchRequest:fetchIcon error:&error];
if ( [Icon count] !=0 ) {
return Icon[0];
}
return NO;
}