本文共 1905 字,大约阅读时间需要 6 分钟。
typedef struct objc_clas *Class
//Person.h#import@interface Person : NSObject@property int age;+(void)test;@end//Person.m#import "Person.h"@implementation Person+(void)test{ NSLog(@"Person调用了test++++++");}+ (void)load{ NSLog(@"Person----load");}+(void)initialize{ NSLog(@"Person---initialize");}@end
//Student.h#import "Person.h"@interface Student : Person@end//Student.m#import "Student.h"@implementation Student+(void)load{ NSLog(@"Student---load");}+(void)initialize{ NSLog(@"Student---initialize");}@end
//GoodStudent.h#import "Student.h"@interface GoodStudent : Student@end//GoodStudent.m#import "GoodStudent.h"@implementation GoodStudent+(void)load{ NSLog(@"GoodStudent---load");}+(void)initialize{ NSLog(@"GoodStudent---initialize");}@end
//Person+MJ.h#import "Person.h"@interface Person (MJ)@end//Person+MJ.m#import "Person+MJ.h"@implementation Person (MJ)+(void)load{ NSLog(@"Person(MJ)---load");}+(void)initialize{ NSLog(@"Person(MJ)---initialize");}@end
Person *p1=[[Person alloc]init]; Person *p2=[[Person alloc]init]; Person *p3=[[Person alloc]init]; Class c1=[p1 class]; Class c2=[p2 class]; Class c3=[Person class]; NSLog(@"c1=%p,c2=%p,c3=%p",c1,c2,c3);
Person *p=[[Person alloc]init];Class c=[p class]; [Person test];[c test]; Person *p2=[[c new]init]; NSLog(@"Person ---%d",p2.age);
//方式一Class c=[Person class];//类方法方式二Person *p=[Person new];Class c2=[p class];//对象方法
转载地址:http://jjik.baihongyu.com/