开发者

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

开发者 https://www.devze.com 2023-03-22 07:42 出处:网络
this is my piece of code: NSUInteger indexArr[] = {1,2,3,4}; NSIndexSet *indexSet =开发者_运维技巧 [NSIndexPath indexPathWithIndexes:indexArr length:4];

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


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];
0

精彩评论

暂无评论...
验证码 换一张
取 消