Objective-C Finding an NSArray for a String?

I have an array of strings.

How can I determine which index contains a string in an array?

+4
arrays find iphone
Aug 27 2018-10-10T00:
source share
2 answers
+10
Aug 27 2018-10-21T00:
source share

Although very old, but this question is quite high in Google search. Here is the version in use of the block,

 - (void)testSearch { NSArray *hashAlgorithms = @[@"SHA1", @"SHA2", @"SHA256", @"SHA384", @"SHA512"]; NSString *searchFor = @"SHA384"; __block NSInteger index = NSNotFound; [hashAlgorithms enumerateObjectsUsingBlock:^(id alg, NSUInteger idx, BOOL *stop) { if ([alg compare:searchFor options:NSCaseInsensitiveSearch] == NSOrderedSame) { NSLog(@"Found: %@", searchFor); *stop = YES; index = idx; } else { NSLog(@"NOT Equal: %@", alg); } }]; if (index == NSNotFound) { NSLog(@"Not found. %li", (long)index); } else { NSLog(@"Found at: %li", (long)index); } } 
+1
Jul 28 '15 at 12:56
source share



All Articles