iOS Open Source: Access arrays using ruby range syntax

June 26, 2013

Leveraging object subscripting, Rounak Jain wrote a category on NSArray that provides access to a range of values in a manner similar to Ruby (.. syntax).

NSArray *array = [NSArray arrayWithObjects:@"porter",@"ipa",@"stout",@"pale ale",@"pilsner", nil];
NSLog(@"%@",array[@"2..4"]);

Range checking would be a nice addition, as well as support for syntax, where the starting value is included but not the ending value.

NSArraySubarraySubscripts on github