Quick question for you. I want to be able to create an instance of an object. The object type is based of a string.
In php you can just replace the class name with a string, but I doubt it is that easy in Objective c.
NSString * className;
id theObject;
className = @"TestObject";
theObject = [[className alloc] init];
here is a break down of what it might look like. I want to try and avoid using a giant case style statement.
Is it possible to use the selector system for this?
any ideas?
Cheers
You can get a class by its name using one of the following obj-c runtime functions (you may need to import header:
So your code may look like (have not tested it though):
You can get a
Class
object dynamically withNSClassFromString()