在 Objective-C 中跟踪类实例的最佳方法是什么?
我正在制作一个应用程序,该应用程序使用一个名为 Player 的类,Player 实例的数量最多可达 10 个,最多可达 2 个。我想知道跟踪所有这些实例的最佳方法是什么?现在我只是在视图控制器中创建一个数组,我可以根据需要添加和删除该数组,但是有更好的方法吗?我想知道是否存在类变量和类方法之类的东西?
提前致谢。
I am making an app that uses a class I will call Player the number of Player instances can go up to 10 and down to 2. I am wondering what is the best way to keep track of all of these instances? For now I am just making an array in my view controller that I can add to and remove from as necessary, but is there a better way? I was wondering if there is such a thing as class variables as there are class methods?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我发现我需要做的是创建另一个对象来管理我的子对象。即玩家跟踪每个玩家实例。我是 OOP 世界的新手,但我想我正在解决问题。
I discovered that what i needed to do was create another object to manage my child objects. ie Players keeps track of each player instance. I'm new to this OOP world but I think Im figuring things out.
在 Objective-C 中,静态方法被称为类方法。它们都将通过类名来调用。
例如:
In objective-C the static methods are called as class methods. They all will be called by the class name.
eg:
您可以同步类变量的属性,然后使用它们。
You can synchronize properties for your class variables and then use them.