bee框架学习笔记
来源:互联网 发布:解放军的无人机 知乎 编辑:程序博客网 时间:2024/05/17 21:07
问题:为什么AppService类中的+(void)initialize{}函数会先于AppDelegate类的- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions执行??
解答:程序一运行的时候会先加载bee框架,会执行到bee框架里面的Bee_Runtime.mm这一个文件里的如下一个函数:
+ (NSArray *)allClasses{static NSMutableArray * __allClasses = nil;if ( nil == __allClasses ){__allClasses = [[NSMutableArray alloc] init];}if ( 0 == __allClasses.count ){unsigned intclassesCount = 0;Class * classes = objc_copyClassList( &classesCount );for ( unsigned int i = 0; i < classesCount; ++i ){Class classType = classes[i]; //other codes}free( classes );}return __allClasses;}
其中 objc_copyClassList( &classesCount )这个函数,会创建并返回一个指向所有已注册类定义的指针列表。
当它循环遍历指针列表的时候,遍历到一个指向AppService的类,然后就会执行Appservice类中的+(void)initialize{}函数(why?see introduce of initialise below),执行完Bee框架里的东西之后程序才会去执行- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions,导致先执行AppService类的+(void)initialize{}函数,然后才执行AppDelegate类的- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions执行
附注:
关于 objc_copyClassList 和 initializer 函数的介绍,摘录苹果官网的介绍如下:
Class *objc_copyClassList(unsigned int *outCount)
Description
Creates and returns a list of pointers to all registered class definitions.
See Also: objc_getClassList
Parameters
outCount
An integer pointer used to store the number of classes returned by this function in the list. It can benil.
Returns
A nil terminated array of classes. It must be freed with free().
Declaration
+ (void)initialize
Description
Initializes the receiver before it’s used (before it receives its first message).
The runtime sends initialize to each class in a program exactly one time just before the class, or any class that inherits from it, is sent its first message from within the program. (Thus the method may never be invoked if the class is not used.) The runtime sends the initialize message to classes in a thread-safe manner. Superclasses receive this message before their subclasses.
initialize it is invoked only once per class. If you want to perform independent initialization for the class and for categories of the class, you should implementload methods.
- bee框架学习笔记
- POJ 1518 Problem Bee 笔记
- POJ 1518 Problem Bee 笔记
- POJ 3102 Bee Garden 笔记
- bee
- bee
- Bee
- android ios 快速开发框架Bee Framework
- iOS快速开发框架--Bee Framework
- iOS快速开发框架--Bee Framework
- beego框架利用bee api创建api框架
- iOS快速开发框架Bee-Framework应用和解析(一) --- 为什么使用Bee framework
- iOS快速开发框架Bee-Framework应用和解析(二) --- Bee framework架构概览
- iOS快速开发框架Bee-Framework应用和解析(二) - Bee framework架构概览
- beego和bee的安装、自动生成API框架
- spring框架学习笔记
- Struts框架学习笔记
- 框架-Struts2 学习笔记
- POJ 3321 Apple Tree(dfs+树状数组)
- 较老版本的AFNetworking使用心得
- 支付宝集成错误
- Ogre水面倒影的实现
- c++字符串替代源码
- bee框架学习笔记
- Spring MVC3在controller和视图之间传递参数的方法
- 循序渐进开发WinForm项目(4)--Winform界面模块的集成使用
- -------------Android判断应用或Activity的存在性
- pds 1112 bfs
- 机器人
- 找回丢失已久的输入法状态条
- ZOJ3471
- iOS7Bug UINavigationController push一个controller的时候 会出现屏幕卡顿一下