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); } }
karim Jul 28 '15 at 12:56 2015-07-28 12:56
source share