NSClassFromString() vs classNamed:(NSString *)

泄露秘密 提交于 2020-01-01 09:43:09

问题


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 *)?


回答1:


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.



来源:https://stackoverflow.com/questions/6524165/nsclassfromstring-vs-classnamednsstring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!