Created
September 14, 2011 18:46
-
-
Save zwaldowski/1217400 to your computer and use it in GitHub Desktop.
Block-based enumeration for NSRange
This file contains hidden or 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
// | |
// NSEnumerateRange.m | |
// | |
// Created by Zachary Waldowski on 9/14/11. | |
// Copyright 2011 Dizzy Technology. Licensed under MIT. | |
// | |
NS_INLINE void NSEnumerateRange(NSRange range, void (^block)(NSUInteger idx, BOOL *stop)) { | |
block = Block_copy(block); | |
NSUInteger start = range.location; | |
for (NSUInteger i = 0; i < range.length; i++) { | |
NSUInteger idx = start + i; | |
BOOL stop = NO; | |
block(idx, &stop); | |
if (stop) | |
break; | |
} | |
Block_release(block); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment