Objective C - 如何定义类中所有方法都可以访问的静态数字数组?
我如何定义一个可由我的类中的所有方法访问的静态数字数组???
How can i define a STATIC array of numbers accessible to all methods in my class???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
与在 C 中执行此操作的方式相同:
如果您想要一个静态 NSArray,则必须采取一些技巧。 Objective-C 中的对象类型不允许使用
static
(因为你不能直接声明对象 - 只能声明指针)。在这种情况下,您需要阅读 Objective-C 单例。实现它的快速方法:当然,您可以将其设置为使用您想要的任何类型的对象进行初始化。
The same way you'd do it in C:
If you want a static
NSArray
, you'll have to do some tricks.static
isn't allowed for object types in Objective-C (since you can't declare an object directly - only pointers). In that case, you need to read up on Objective-C singletons. A quick way to implement it:You can, of course, set it up to initialize with whatever kind of objects you'd like.