iOS开发那些事iOS技术点

Object Runtime

2017-01-06  本文已影响48人  AKyS佐毅

Object Runtime

int main(int argc, char * argv[]) {
    
    NSLog(@"%s",__func__);
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}
#import "Person.h"

@implementation Person

+ (void)load{
    NSLog(@"%s",__func__);
}

+ (void)initialize{
    [super initialize];
    NSLog(@"%s %@",__func__,[self class]);
}

- (instancetype)init{
    if (self = [super init]) {
        NSLog(@"%s",__func__);
    }
    return self;
}

@end
@implementation Girl

+ (void)load{
    NSLog(@"%s ",__func__);
}

+ (void)initialize{
    [super initialize];
    NSLog(@"%s ",__func__);
}

- (instancetype)init{
    if (self = [super init]) {
        NSLog(@"%s",__func__);
    }
    return self;
}

@end

执行操作

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    Person * p1 = [Person new];
    Person * p2 = [Person new];
    Girl *c1 = [Girl new];
    Girl *c2 = [Girl new];
}
@end

执行结果:

+[Person load]
+[Girl load]
main
+[Person initialize] Person
-[Person init]
-[Person init]
+[Person initialize] Girl
+[Girl initialize]
-[Person init]
-[Girl init]
-[Person init]
-[Girl init]
上一篇 下一篇

猜你喜欢

热点阅读