2012-08-09 2 views

답변

13

이 가장 경제적으로 트릭을 할 것 [테스트] :

[myArray filteredArrayUsingPredicate:[NSPredicate 
    predicateWithFormat:@"self == %@", @"New"]]; 
0

내가 술어 블록

[array filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary * bindings){ 
    [evaluatedObject isEqual:anObject]; 
}]]; 
를 사용하여 배열을 필터링 제안 단지 객체의 빠른 열거하지 왜
1

?

NSMutableArray *matchingObjects = [NSMutableArray array]; 
NSArray *objects = [NSArray arrayWithObjects:@"New", @"Old", @"Future", nil]; 
NSInteger count = 0; 
for (NSString *string in objects) { 
    if ([string isEqualToString:@"New"]) { 
     [matchingObjects addObject:string]; 
    } 
    count++; 
} 

이 방법 matchingObjects 시험과 일치하는 모든 개체를 포함, 당신은 모든 경기의 인덱스를 얻을 수 count를 사용할 수 있습니다. 당신이 동일한 개체에

NSString *str1 = @"New"; 
NSString *str2 = @"New"; 

그런 str1str2 점으로 트릭을 할 것입니다 다음 @"New" 같은

int index = [array indexOfObject:@"New"]; 

을 상수 문자열을 추가 한 경우

+0

좋은 ans, [string containsString :] 메서드로도 객체를 필터링 할 수 있습니다. –

3

는 피나.
그리고 당신이 찾고있는 문자열을 알고 있다면 그것을 찾을 필요가 있습니까?
먼디의 대답도 좋습니다.

관련 문제