2014-02-13 2 views
0

내부 배열을 찾을 I * 있는 NSString * 번호 NSSet이 들어있는 DB 내가 쉽게와 문자열 번호를 기준으로 모든 결과를 얻을 수 있습니다자 NSPredicate는 DB

값이 다음

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"Number LIKE[c] %@", numberValue]; 
NSArray *result = [DB MR_findAllWithPredicate:predicate inContext:_context]; 

Number 대신 값의 배열을 전달하려면 주어진 배열 (NSSet)을 포함하는 모든 결과를 db에서 어떻게 찾을 수 있습니까?

NSPredicate *predicate = [NSPredicate predicateWithFormat: ???? 
NSArray *result = [DB MR_findAllWithPredicate:predicate inContext:_context]; 

Igoris의 답변에 따라

UPDATE이 보이는

[NSPredicate predicateWithFormat:@“([email protected] == %d) AND (SUBQUERY(Values, $x, $x IN %@)[email protected] == %d)", allValues.count, allValues, allValues.count]; 

이 작동하는 있지만 t이 결과의 모든 값을 반환 아무튼. 나는 다음과 같은 술어를 내놓았다 데이터 구조 해명 후

이 얻을 : 당신이

가 UPDATE

를 찾고 있습니다

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"Number IN[c] %@", numberValues]; 

있는 NSArray가 포함되어 numberValues 번호 :

답변

0

그냥 IN를 사용 객체 :

[NSPredicate predicateWithFormat:@“([email protected] == %d) AND (SUBQUERY(Values, $x, $x IN %@)[email protected] == %d)", allValues.count, allValues, allValues.count]; 
+0

numberValues는 NSSet입니다. 그냥 문자열처럼 추가해도 괜찮습니까? –

+0

IN은 NSSets와 잘 작동합니다. Apple docs : Objective-C에서는 다음 예제와 같이 IN 술어를 만들 수 있습니다. NSPredicate * inPredicate = [NSPredicate predicateWithFormat : @ "attribute, IN % @", aCollection]; 여기서 aCollection은 NSArray, NSSet, NSDictionary 또는 해당하는 변경 가능한 클래스의 인스턴스가 될 수 있습니다. – igoris

+0

내 DB에는 Studends라는 클래스가 있습니다. 각 Student에는 Number라는 NSSet과 Notes라는 NSSet이라는 클래스가 있습니다. 모든 학생을 (NSSet with value 10) –

0

어때요?

[NSPredicate predicateWithFormat:@"ANY number == %@", numberValues]; 
+0

Igoris 응답이 올바른 것 같습니다 [NSPredicate predicateWithFormat : @ "(값. @ 개수 == % d) 및 (부울 값 ($ x, $ x IN % @). @ count == % d)", allValues. count, allValues, allValues.count]; 그러나 하나의 값만 응답으로 반환합니다. –

관련 문제