XCode/iOS:遍历给定类的所有实例? [英] XCode / iOS: Iterating through all instances of a given class?

查看:42
本文介绍了XCode/iOS:遍历给定类的所有实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 iPhone 开发 3D 游戏引擎,目前正在研究如何处理我的所有 3D 对象.我有一个类,其中包含与每个3D对象有关的信息,例如顶点数据,纹理信息等.

I am working on a 3d game engine for the iPhone and Im currently working out how Im going to be handling all of my 3D objects. I have a class that holds information pertaining to each 3D object such as vertexdata, texture information, etc.

我还有一个每 x 毫秒调用一次的方法来处理渲染 3d 场景.

I also have a method that is called once every x milleseconds that handles rendering the 3d scene.

在此方法中,我想遍历所有3D对象以访问其渲染数据.

Inside of this method, I would like to loop through all of my 3D objects to get access to their render data.

我意识到我可以将指向所有3D对象的指针存储在数组中并遍历该数组,但是在尝试走这条可能不必要的道路之前,我想知道是否有可以简单地遍历给定类的所有实例的方法(即我的3d对象类),因为这可以解决我的问题.

I realize I could store pointers to all of my 3D objects in an array and iterate through this array, but before venturing down this possibly unnecessary road I was wondering if there was away to simply iterate through all instances of a given class (ie my 3d object class), as this would solve my problem.

佩斯多:

对于(AEobject3D中的obj){

For (obj in AEobject3D){

渲染obj

}

像这样可能吗?如果是这样,请原谅无知,我似乎无法在文档/互联网中找到信息,而我仍在通过Objective C学习自己的方式.

Is something like this possible? If so please excuse the ignorance, I cant seem to find information in the docs / internet, and Im still learning my way through Objective C.

谢谢,-亚当·埃斯费尔德

Thanks, - Adam Eisfeld

推荐答案

否,没有内置的方法可以做到这一点.如果你想自己实现它,你仍然需要使用一个数组来跟踪对象.因此,我建议您首先使用数组.

No, there's no built-in way to do this. If you wanted to implement it yourself, you'd still have to use an array to keep track of the objects. So I suggest you just use an array in the first place.

这篇关于XCode/iOS:遍历给定类的所有实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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