Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

allocing an object based on a string name

Is there a way in objective-c/Cocoa to alloc an object when the class name isn't know until run-time. I seem to remember something about this a while ago, but can't find anything on it now.

Something like:

[[@"MyClass" alloc] init];

I seem to recall a function that would return some kind of class id based on a string that can then be used to alloc the object.

like image 385
Roger Gilbrat Avatar asked Jan 23 '23 07:01

Roger Gilbrat


1 Answers

id object = [[NSClassFromString(@"MyClass") alloc] init];
like image 158
Dave DeLong Avatar answered Feb 02 '23 19:02

Dave DeLong