Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to declare good old C-Array in Objective-C inline?

this is my piece of code:

NSUInteger indexArr[] = {1,2,3,4};

NSIndexSet *indexSet = [NSIndexPath indexPathWithIndexes:indexArr length:4];

Is there a way to declare the indexArr inline, like

NSIndexSet *indexSet = [NSIndexPath indexPathWithIndexes:{1,2,3,4} length:4];

or something? It's because I'm writing a test with some reference Paths and I want to save lines of code that are not usefull for anybody...

Best regards, hijolen

like image 645
monavari-lebrecht Avatar asked Jul 21 '11 04:07

monavari-lebrecht


1 Answers

The only problem with your attempt is that you need to cast it so that the compiler knows it is the right type.

NSIndexSet *indexSet = [NSIndexPath indexPathWithIndexes:(NSUInteger[]){1,2,3,4} length:4];
like image 59
ughoavgfhw Avatar answered Nov 19 '22 08:11

ughoavgfhw