开发者

Class type Objective C

开发者 https://www.devze.com 2023-01-12 08:16 出处:网络
In the NSObject protocol, it defines a meth开发者_运维百科od that is similar to this: -(Class) class

In the NSObject protocol, it defines a meth开发者_运维百科od that is similar to this:

-(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?


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"

You can do all kinds of introspection/reflection with Class objects; see the Objective-C runtime reference for details.


It is now

NSObject *o = [[NSObject alloc]init];
NSLog(@"%s\n", object_getClassName([o class]));

object_getClassName instead of class_getClassName

0

精彩评论

暂无评论...
验证码 换一张
取 消