class && metaClass

大家都用这个图我也用这个图吧


class && metaClass_第1张图片
class-diagram.jpg

Aclass *aclass = [[Aclass alloc] init];
Class cls = object_getClass(aclass); //Aclass(Class)
const char *Aclass1 = class_getName(cls); //"Aclass"
NSLog(@"1=:%s",Aclass1);
BOOL f1 = class_isMetaClass(cls); //NO
NSLog(@"f1=:%d",f1);

Class meta = object_getClass(cls); //Aclass(meta-class)
const char *Aclass2 =class_getName(meta);               //"Aclass"
NSLog(@"2=%s",Aclass2);
BOOL f2 = class_isMetaClass(meta);            //YES
NSLog(@"f2=:%d",f2);

Class meta_meta = object_getClass(meta); //NSObject(meta-class)
const char *Aclass3 = class_getName(meta_meta);//"NSObject"
NSLog(@"3=:%s",Aclass3);
BOOL f3 =  class_isMetaClass(meta_meta);//YES
NSLog(@"f3=:%d",f3);

打印信息
1=:Aclass
f1=:0
2=Aclass
f2=:1
3=:NSObject
f3=:1

你可能感兴趣的:(class && metaClass)