코어 데이터 저장소를 쿼리하는 데 NSPredicate를 사용하고 있습니다. NSNumber 유형의 저작물을 보유하고 있습니다. 나는 시도 1.NSPredicate를 사용하여 여러 값 반환
동일 모든 부가 요소를 얻으려면 :
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"attribute == %i", i];
어디에서 = 1
이 작동하지만 그것은 단지 일치하는 속성을 가진 첫 번째 개체를 반환합니다. 이 속성이 1 인 모든 객체를 원합니다.
어디서 잘못 되었나요? 쿼리 앞에 ALL을 넣으려고했지만 충돌이 발생했습니다.
업데이트 :
이 내 전체 코드입니다 : 다음
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Person"
inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];
[fetchRequest setResultType:NSDictionaryResultType];
NSNumber *attributeValue = [NSNumber numberWithInt:1];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"attribute == %@",
attributeValue];
[fetchRequest setPredicate:predicate];
NSError *error = nil;
NSArray *fetchResults = [managedObjectContext executeFetchRequest:fetchRequest
error:&error];
return [fetchResults objectAtIndex:0];
그리고 :
NSDictionary *dict = [self queryContextWithQuery:nil];
NSLog(@"%@", dict);
로그 만 보여줍니다 1이 표시되어야합니다 3 가능한 객체 중.
술어에 대한 구현되지 않은 SQL 생성 –
@kmcgrady 왜 그런 오류가 발생하는지 확신 할 수없는 ==를 변경하려고합니다. –
원래 코드처럼 작동합니다. 기준과 일치하는 3 대신 1 개의 객체 만 반환합니다. –