2012-04-30 3 views
0

NSString 객체가있는 NSMutableArray가 있습니다. 문자열을 포함하지 않는 객체 만 가져 오도록 필터링하려면 어떻게해야합니까? 나는 문자열을 포함하는 객체 필터링 자 NSPredicate을 시도 :문자열을 포함하지 않는 NSMutableArray 객체를 필터링하는 방법은 무엇입니까?

NSString *match = @"My text"; 

    NSPredicate *sPredicate = [NSPredicate predicateWithFormat:@"SELF CONTAINS[cd] %@", match]; 

    [self.filesList setArray:[self.filesList filteredArrayUsingPredicate:sPredicate]]; 

유사한 있나요,하지만 그 반대를 필터링 할 수 있습니까? 어떤 종류의 "! contains"?

+0

가능한 중복 http://stackoverflow.com/questions/1166401/writing-an-nspredicate - 그 조건을 충족시키지 못하면 true를 반환합니다) – jtbandes

답변

2

사용이 대신 : ([조건이 충족되지 않을 경우에 true를 반환하는 자 NSPredicate 쓰기]를의

NSPredicate *sPredicate = [NSPredicate predicateWithFormat:@"NOT (SELF CONTAINS[cd] %@)", match];

+0

고마워요! 그것은 작동합니다! 또한 문자열을 포함하는 객체로 새 배열을 만든 다음 removeObjectsInArray를 사용하여 새 배열을 만들 수도 있습니다 – Oleg

관련 문제