NSClassFromString()vs classNamed:(NSString *) [英] NSClassFromString() vs classNamed:(NSString *)

查看:145
本文介绍了NSClassFromString()vs classNamed:(NSString *)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从我所看到的,似乎有两种方法可以从类名中获取对象。使用 NSClassFromString() NSBundle 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 *)?

推荐答案

NSClassFromString()返回已经在给定名称的运行时注册的类。 NSBundle的 classNamed:返回包中具有给定名称的类,可能尚未加载(这意味着如果需要,它将加载该包)。

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).

但是不同的方式:NSBundle可能不知道应用程序运行时中加载的所有类(尽管如果它是主要的包,它可能知道大部分的类)。相反,您的应用程序的运行时将不会知道捆绑包中的所有类加载之前。

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.

这篇关于NSClassFromString()vs classNamed:(NSString *)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆