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 an indexArr string like

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

or something else? This is because I am writing a test with some reference paths, and I want to save lines of code that are not useful to anyone ...

Regards, hijolen

+5
source share
1 answer

The only problem with your attempt is that you need to give it away so that the compiler knows that it is the correct type.

NSIndexSet *indexSet = [NSIndexPath indexPathWithIndexes:(NSUInteger[]){1,2,3,4} length:4];
+11
source

All Articles