如何申报在Objective-C直列好老的C-阵列? [英] How to declare good old C-Array in Objective-C inline?

查看:181
本文介绍了如何申报在Objective-C直列好老的C-阵列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的作品code的:

this is my piece of code:

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

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

有没有申报indexArr内联,如

Is there a way to declare the indexArr inline, like

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

还是什么?
这是因为我正在写具有一定的参考路径的测试,我想节省$ C $行C未有用任何人...

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...

最好的问候,hijolen

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

这篇关于如何申报在Objective-C直列好老的C-阵列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆