Skip to content

Instantly share code, notes, and snippets.

@zwaldowski
Created September 14, 2011 18:46
Show Gist options
  • Save zwaldowski/1217400 to your computer and use it in GitHub Desktop.
Save zwaldowski/1217400 to your computer and use it in GitHub Desktop.
Block-based enumeration for NSRange
//
// 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