Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Continuous numbers in Objective-C array like range() in Python

Python can make a list with continuous numbers like this:

numbers=range(1,10); // >> [1,2,3,4,5,6,7,8,9]

How to implement this in Objective-c?

like image 618
Mil0R3 Avatar asked Aug 03 '12 09:08

Mil0R3


1 Answers

Reading your statement " Just need an array with continuous numbers,I do not want to init it with a loop" lets me ask: what is more important for you: to have an array or to have "something" that represents a continuous range of (natural) numbers. Have a look at NSIndexSet It may come close to what you want. You initialize it with

[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1,9)]; 

Iterating over this set is as simple as iterating over an array and does not need NSNumbers.

like image 196
Heinrich Giesen Avatar answered Sep 19 '22 10:09

Heinrich Giesen