DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Ivor has posted 7 posts at DZone. View Full User Profile

Objective-C: Dynamic Instantiation

02.14.2010
| 1350 views |
  • submit to reddit
        //Class cl = [Foo class];
//Class cl = NSClassFromString(@"Foo");
Class cl = [[NSBundle mainBundle] classNamed: @"Foo"];
	
NSLog(@"cl=%@", cl);
	
NSObject *obj = [[cl alloc] init];

NSLog(@"obj=%@", obj);