Created
April 26, 2013 06:54
-
-
Save rbarbera/5465425 to your computer and use it in GitHub Desktop.
Stopping an enumerateObjectUsingBlock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// main.m | |
// enumeration | |
// | |
// Created by Rafa Barberá on 26/04/13. | |
// Copyright (c) 2013 Rafa Barbera. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
#import <Cocoa/Cocoa.h> | |
int main(int argc, const char * argv[]) | |
{ | |
@autoreleasepool { | |
NSArray *array = [@"May the force be with you" componentsSeparatedByString:@" "]; | |
__block NSUInteger forceIndex = -1; | |
[array enumerateObjectsUsingBlock:^(NSString *word, NSUInteger idx, BOOL *stop) { | |
if ([word isEqualToString:@"force"]) { | |
forceIndex = idx; | |
*stop = YES; | |
} | |
}]; | |
NSLog(@"You've stopped at index %ld by word [%@]",forceIndex,array[forceIndex]); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment