2014-06-20 2 views
-2

NSPredicate Object를 만들려고합니다. 나는 아래에 나의 코드를 주었다. 나는 왜 항상 nil을 얻는가? 그것을 할 다른 방법이 있습니까?NSPredicate는 항상 nil입니다.

NSString *[email protected]"Deva"; 
NSString *predicateString=[NSString stringWithFormat:@"name contains[c] '%@'",name]; 
NSPredicate *namepredicate=[NSPredicate predicateWithFormat:predicateString];` 
+0

비교 대상 값은 무엇입니까? "Deva"가 일치하는 데이터에 없으면 아무 것도 표시되지 않습니다. – brandonscript

+1

왜이 방법으로 당신의 술어를 구축하고 있습니까? 이름이 "오쇼 너시"라면? NSPredicate는 다음 형식을 취한다. [NSPredicate predicateWithFormat : @ "name contains [c] % @", name]' –

+0

또한, 나는'namepredicate! = nil'을 시도했다. 무슨 문제 야? –

답변

0

조건 자의 형식을 변경해야합니다. 술어를 사용할 때 첫 번째 변수 ('name'의 경우)는 객체에서 가져 오는 속성입니다. String에서는 속성 이름이 없습니다. 시도 :

NSString *name = @"Deva"; 
    NSPredicate *namepredicate=[NSPredicate predicateWithFormat:@"(self contains[c] %@)",name]; 
    arr = [arr filteredArrayUsingPredicate:namepredicate]; 
관련 문제