iPhone OS SDK – Searching for an item in an array

7/04/2010

In my latest iPad application Design Brief, I required a way to search an array to check its contents for a value. I found this is how it is done.

NSArray *array = [NSArray arrayWithObjects: @"One", @"Two", @"Three", @"Four", nil];

for (NSString *element in array) {
if ([element isEqualToString:@"Three"]) {
NSLog(@”Found Three!”);
break;

}

}

The reference unfortunately alludes me, but it was a published book. If a commenter notes it, I will credit it.

No comments yet.

Write a comment:

blog comments powered by Disqus