views:

236

answers:

1

I was wondering if i could create a object of some class if i have the name of the class in a NSString. I know this is possible in other languages like ActionScript, C# and PHP...

Something like this:

NSString *className = @"AwesomeViewController";
UIViewController *object = [[className alloc] initWithNibName:className bundle:nil];
+7  A: 

Classes are first-class objects in Obj-C too. You can get the class object from an NSString with the NSClassFromString function.

[[NSClassFromString(className) alloc] init...]
KennyTM
Work like a charm :)
Sveinn Fannar