Comparison of Load methods and initialize methods
in the OC language, we compared to the load and initialize method use less, so it will not be very clear about the use and difference between the two, so tidy up a bit, and we share, there is the wrong place, I hope to point out, thank you!
1. Load method Features:
1> executes this function when the class is referenced into the program
2> the Load method of a class does not specify [super Load], the parent class receives the call, and precedes the child class.
The load of the 3> category will also receive calls, but in order after the main class's load call.
2, Initialize method features:
The natural invocation of 1> initialize is the first time that the current class is actively used
2> and load are different, even if the subclass does not implement the Initialize method, the implementation of the parent class is inherited to call it over. Note that before this, the method of the parent class has been executed once, and no super call is required.
3, load and initialize have a lot of common characteristics, the following simple list
1> the system will call at most once without considering the developer's active use
2> if both the parent class and the child class are called, the call of the parent class must precede the child class
3> to create the right environment for the application to run ahead of time
4> do not rely heavily on these two methods when used, unless it is really necessary to
Due to these characteristics of initialize, the application is slightly more extensive than load. Can be used to do some initialization work, or a singleton mode of implementation of the scheme. This single-case approach will be mentioned later.
To summarize: The load method invokes the contents of the program when it is loaded (without making a manual call) and the entire program is called only once, and initialize (more difficult English words) The method is called only once when the program uses the class that contains it. So in the process of development, we can make use of his whole character, and write some methods in it, which will make the app run faster. For example, in the development of our use of database operations, will cache a large amount of data, when the user has just started to open the app, if processed, then it will produce the beginning of the use of time, a few seconds, it is loading data, but this data we open the app can not be used, Therefore, we will write the database related operations in the initialize , so that when the use of the data cache, will improve the performance of the entire app.
If there is no wrong, please give me a message, I very much like to discuss technology with others, hope to progress together.
iOS Development-oc article Load method and initialize method comparison