Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - Initializing an NSArray with a sequence of numbers

I'm looking to do something in Objective C equivalent to the following MATLAB command:

A=4:7; 

In this case, the variable A then becomes an array with elements [4 5 6 7].

Is there any shorthand way to set an NSArray with a sequence of numbers like this in Objective C? Thanks for reading!

like image 898
Rogare Avatar asked Feb 14 '26 04:02

Rogare


1 Answers

Use a NSIndexSet as the object in the array - you can then use:

[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(4, 4)];
like image 113
David H Avatar answered Feb 15 '26 19:02

David H



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!