I know how to do it in Ruby, converting a range of numbers to an array. But how is it possible in Objective-C?
Ruby:
(1..100).to_a
You've got to do it manually:
// Assuming you've got a "NSRange range;"
NSMutableArray *array = [NSMutableArray array];
for (NSUInteger i = range.location; i < range.location + range.length; i++) {
[array addObject:[NSNumber numberWithUnsignedInteger:i]];
}
You might want to try NSIndexSet
instead.
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, 100)];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With