iOS-底层探索11:dyld流程分析
2020-09-28 本文已影响0人
differ_iOSER
一、前言
本篇文章大概学习dyld相关的知识
iOS 代码如下:
@implementation ViewController
+ (void)load{
NSLog(@"%s",__func__);
}
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"%s",__func__);
}
@end
main 文件:
int main(int argc, char * argv[]) {
NSLog(@"main");
NSString * appDelegateClassName;
@autoreleasepool {
// Setup code that might create autoreleased objects goes here.
appDelegateClassName = NSStringFromClass([AppDelegate class]);
}
return UIApplicationMain(argc, argv, nil, appDelegateClassName);
}
// 定义一个C++方法
__attribute__((constructor)) void testFunc() {
printf("来了 : %s \n",__func__);
}
运行程序后打印顺序:
+[ViewController load]
来了 : testFunc
main
-[ViewController viewDidLoad]
由此可知加载顺序为load -> Cxx -> main