创建一个对象,奇怪的问题
我有一个类“Projectiles”,我想用它创建一个对象。 为了最小化代码,我想从字符串中指定对象,这会清理很多东西。
例子: 我有字符串,
tempenemy.atktype = @"homing_fireball";
现在我想从 Projectiles 类创建一个同名的对象:
Projectiles *tempenemy.atktype;
这可能吗?那么最终结果将是来自 Projectiles 类的一个名为 homing_fireball 的对象..?
谢谢!!
I have a class "Projectiles", and I want to create an object with it.
To minimise code, I want to specify the object from a string, it would clean up thins alot.
Example:
I have the string,
tempenemy.atktype = @"homing_fireball";
Now i want to create an object with the same name from Projectiles class:
Projectiles *tempenemy.atktype;
Is this possible? So the final result would be an object from Projectiles class called homing_fireball..?
Thanks!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我怀疑这是可能的。但我不是objective-c内核的专家。
我建议您将 Projectile 存储在 NSMutableDictionary 中。您可以使用@“homing_fireball”键存储该对象。然后你可以用类似的东西来引用它
I doubt that this is possible. But I'm not an expert for the inner core of objective-c.
I would suggest you to store your Projectile in a NSMutableDictionary. You could store the object with a key of @"homing_fireball". And then you can reference it with something like
如果我明白你的意思,你正在尝试初始化一个以 atktype 作为其成员的射弹对象?你在 main 中调用..
你的projectiles.h
你的projectiles.m
If i am getting what you mean, you are trying to init a projectiles object with a atktype as its member? You call in main..
Your projectiles.h
Your projectiles.m