나는 CoreData
에서 1 result
또는 nil
을 기대하고 있습니다. CoreData에서 항상 NSArray를 가져 옵니까?
NSArray
로 가져 오기 설정하고이
IconRoutine*
객체로 가져 오기 위해 서 있지만
[context executeFetchRequest:fetchIcon error:&error];
가 나는 것을 시도 할 때 따라서 충돌의 결과로, 배열로 가져 오기 위해 필요로 나는 시도했다.
은 내가 어쩌면 다른 방법으로 내가 해달라고하는 entity object
에 페치 nil
를 확인하기 위해 if ([Icon count] !=0)
이 필요하고 난 그냥 다른 방법으로 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;
}
WHy -1 ?? ....... –
그게 바로 핵심 데이터가 작동하는 방식입니다. 나는 두려워합니다. 항상 배열로 가져옵니다. –
반환 값'nil'은 "error"를 의미하는 반면, 빈 배열은 "결과 없음"을 의미합니다. –