I'm making a class that initializes instances of certain classes. This class will be used to initialize a few different types of classes all subclassed from a common super class. Currently I am using an instance variable:
Class templateClass;
to store the class type. I get compiler warnings saying methods aren't supported by templateClass. Is there a way to suppress these warnings or specify that the template class must be a subclass of a certain class?
Also, is this the ideal way to go about this in objective-c? Is there a different way to specify the class to use that I should use?
Thanks for the help!
Edit:
The class I am writing is designed to create sprites in randomly chosen locations with a few variables to limit them. This class expects the class it rezzes to have an initWithX:(int)pos yVariance:(int)variance
method. I expect this can be defined using the protocals you mentioned. I will be making multiple instances of the rezzing class for each type of sprite I must create. I want to be able to send the rezzing class initWithTemplateClass:(Class)templateClass
to define the type of sprite to create. I'm not sure if this is the correct way to go about this though because the compiler posts that the method initWithX:(int)pos yVariance:(int)variance
is not available for the templateClass. I expect there is a problem in the way I am going about this.
The code that is showing the warning is:
[self addChild:[[templateClass alloc] initWithX:positionOfChild
yVariance:(random()%(rowVarianceSize+1))]];