0

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!!

1

2 Answers 2

1

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

Projectile *someProjectile = [myProjectiles objectForKey:tempenemy.atktype];
Sign up to request clarification or add additional context in comments.

Comments

0

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..

Projectiles* tempProjectiles = [[Projectiles alloc]initWithType:@"homing_fireball"];

Your projectiles.h

// blah blah blah
{
NSString* atktype;
}
@property (nonatomic, retain)NSString* atktype;
 -(id)initWithType:(NSString*)type;

Your projectiles.m

@synthesize atktype;
-(id)initWithType:(NSString*)type
{
      self = [super init];
         if(self)
          {
             atktype = type;
          }
     return self;
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.