Objective-C 中用户定义类的对象数组?
各位朋友们, 我想为用户定义的类创建数组,就像在java中一样。 例如在java中:
ClassA[] obj=new ClassA[10];
像这样我想在objective-c中创建一个数组,并且我想在方法中返回这个对象。
例如,在 java 中:
ClassA[] method1()
{
ClassA[] classA=new ClassA[10];
return classA;
}
是否可以在不使用 NSArray 的情况下执行此操作。如果可能的话,我怎样才能在 Objective-C 中做到这一点。
请给我一些示例代码片段。 提前致谢。
hai folks,
i want to create array for user defined class like in java.
eg in java:
ClassA[] obj=new ClassA[10];
like this i want to make a array in objective-c, and also i want to return this object in the method.
eg in java:
ClassA[] method1()
{
ClassA[] classA=new ClassA[10];
return classA;
}
is it possible to do this one, without using NSArray. if it possible, how can i do this one in objective-c.
plz give me some sample code snippet for this.
thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
很少有理由避免使用 NSArray。但是,如果您绝对确定遇到其中一种情况,那么请使用 C 习惯用法,因为 Obj-C 是 C 的超集。
There is rarely a reason to avoid NSArray. However, if you are absolutely certain that you have one of those cases, then use the C idiom, because Obj-C is a superset of C.
您可以用 C 风格来实现:
通过这种方式,您可以声明一个指向大小为 10 的
ClassA
对象的指针数组。You can do it in C style:
In this way you are declaring a array of pointers to
ClassA
objects of size 10.