类类型Objective C [英] Class type Objective C
问题描述
在 NSObject
协议中,它定义了类似于以下的方法:
In the NSObject
protocol, it defines a method that is similar to this:
-(Class) class
Class对象是什么类型的对象?或者甚至是一个对象?我可以用对象做什么?
What type of object is the Class object? Or is it even an object? What can I do with the object? Can I get the base class or adopted protocols?
推荐答案
类
是本身是由 Objective-C运行时定义的类,类似于Java中的 Class
类。例如,您可以使用 class_getClassName()
获取类的名称:
Class
is itself a class defined by the Objective-C runtime, akin to the Class
class in Java. For example, you can use the function class_getClassName()
to get the name of a class:
NSObject *o = [[[NSObject alloc] init] autorelease];
NSLog(@"%s\n", class_getClassName([o class])); // prints "NSObject"
您可以使用 Class
objects;有关详细信息,请参阅Objective-C运行时参考。
You can do all kinds of introspection/reflection with Class
objects; see the Objective-C runtime reference for details.
这篇关于类类型Objective C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!