Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSClassFromString() vs classNamed:(NSString *)

From what I have read, there seems to be two ways to get an object from a class name. What are the differences between using NSClassFromString() and NSBundle's classNamed:(NSString *)?

like image 382
Justin Avatar asked Jun 29 '11 16:06

Justin


1 Answers

NSClassFromString() returns a class that has been registered with the runtime for the given name. NSBundle's classNamed: returns the class with the given name inside the bundle, which may not have been loaded yet (which means it will load the bundle if necessary).

But a different way: An NSBundle probably does not know about all the classes loaded in your application runtime (though if it's your main bundle, it probably knows about most of your classes). Conversely, your app's runtime will not know about all the classes in a bundle before it is loaded.

like image 54
Chuck Avatar answered Nov 12 '22 23:11

Chuck