Skip to content

Instantly share code, notes, and snippets.

@rbarbera
Created April 26, 2013 06:54
Show Gist options
  • Save rbarbera/5465425 to your computer and use it in GitHub Desktop.
Save rbarbera/5465425 to your computer and use it in GitHub Desktop.
Stopping an enumerateObjectUsingBlock
//
// 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