In the NSObject
protocol, it defines a method 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?
In the NSObject
protocol, it defines a method 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?
It is now
NSObject *o = [[NSObject alloc]init];
NSLog(@"%s\n", object_getClassName([o class]));
object_getClassName
instead ofclass_getClassName
Class
is itself a class defined by the Objective-C runtime, akin to theClass
class in Java. For example, you can use the functionclass_getClassName()
to get the name of a class:You can do all kinds of introspection/reflection with
Class
objects; see the Objective-C runtime reference for details.