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 *)
?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With