user79854
user79854

Reputation:

Dynamic class creation in Objective-C

Is there an equivalent of selectors for classes? How can I create a instance of a class from a string?

Upvotes: 5

Views: 2417

Answers (1)

Jim Puls
Jim Puls

Reputation: 81052

You want NSClassFromString.

NSString *theClassForMe = @"NSMutableArray";
id newObject = [[NSClassFromString(theClassForMe) alloc] init];

Upvotes: 13

Related Questions