0
전체 문자열 목록에 대해 문자열을 검사하려고합니다. MKMapView가 있는데 많은 결과를 얻었을 때 "Object", "Test", "Example"과 같은 문자열 목록을 포함하는 모든 결과를 제외하고 싶습니다. 따라서 "Object Factory"라는 위치는지도에 표시되지 않습니다. 다른 문자열이 "테스트 영역"이라면 맵에도 표시되지 않습니다. 이상하게 들리는 코드는 "Object", "Test", "Example"을 포함하는 문자열 만 보여주기 때문에 스위치 만해도 표시되는 유일한 문자열이지만이 스위치를 제외한 모든 문자열 보여주기, 그것은 작동하지 않으며 원하지 않는 것을 포함하여 모든 줄이 보여줍니다. 여기문자열 목록에 대한 문자열 확인
NSArray *arrayOfStrings = [[NSArray alloc] initWithObjects:
@"Object",
@"Test",
@"Example",
nil];
for (NSString *s in arrayOfStrings)
{
if ([item.name rangeOfString:s options:NSCaseInsensitiveSearch].location == NSNotFound) {
NSLog(@"Here it is: %@", s);
NSLog(@"Good String");
[self.pastURLs addObject:item.name];
NSLog(@"Here is pastURLS count: %lu", (unsigned long)self.pastURLs.count);
[mapView addAnnotation:annotation];
}
}
그것이 작동 할 때,하지만 잘못된 방법 :
NSArray *arrayOfStrings = [[NSArray alloc] initWithObjects:
@"Object",
@"Test",
@"Example",
nil];
for (NSString *s in arrayOfStrings)
{
if ([item.name rangeOfString:s options:NSCaseInsensitiveSearch].location != NSNotFound) {
NSLog(@"Here it is: %@", s);
NSLog(@"Good String");
[self.pastURLs addObject:item.name];
NSLog(@"Here is pastURLS count: %lu", (unsigned long)self.pastURLs.count);
[mapView addAnnotation:annotation];
}
}