A list or array of consecutive integers

I am new to Objective-C, I have a decent understanding of Ruby.

I want to have a list / array of numbers going from 1, 2, 3, ... up to x (x is the maximum defined elsewhere in my code).

What is the best way to do this (x can be a large number in millions, so manually entering each integer would be undesirable). The rooms are in normal sequence.

In Ruby, I would write something like this:

y = [1..x] 
0
source share
1 answer

Do you really need an NSArray , or only an object representing this range? If this is the latter, you can use NSIndexSet , as in

 NSIndexSet *idxSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, x-1)]; 

If you need NSArray then Josh Caswell links will probably be the best.

+2
source

Source: https://habr.com/ru/post/922031/


All Articles