Edit AllPages


Is there a way to allocate a class based just on its name?

What I would like to do is something like:

CustomObject *myObj = (CustomObject *)@”className” alloc] init];

where className is the name of a sub-class of [[CustomObject;

Any suggestions?


Huibert Aalbers

Yes. See NSClassFromString

Also check out Apple’s documentation on the Objective-C Runtime: also

Thanks a lot, this was very useful. Maybe there should be a reference to this in the Memory management section.

Loading classes at run-time isn’t related to memory management. Memory management deals specifially with keeping track of allocated memory, and knowing when to release that memory.