Many people may ask the difference between the classification and the extension of iOS, many of the explanations on the Internet, but generally are more classified, and this is our usual knowledge of common, but for the expansion, the total understanding of the hazy, not thorough.
Here is my own understanding, but this understanding is also a collection of the experience of predecessors, but I use Dabeivan to extend a little.
For the class extension, look at this paragraph first:
When we define a class, the variables written in. h are not normally called externally, if I have methods that do not want to be externally invoked only for internal use. Thus, the extension appears.
In fact, extension is a kind of seed class similar to "define private method".
For how to create:
Created by the new file , Objective-c extension, for example, I chose the Asstudent class, extension called Hello, then automatically creates an. h file called Asstudent_hello.h,
There is no. m file, because you can write directly in the. m of the class.
In fact, for the only. h file point, many new people may be more confused, only a header file, how and classification is not the same?
This is not the same as the extension, it will create more than one header file, we add the member variables, properties, methods, etc., if you want to implement, you only need to extend the class. m file to implement it.
Sometimes, our online search information, for the extension of the introduction is very common, we may be more confused, do not understand ah ...
In fact, the principle is this:
A: We can actually create an extension without creating a file, and you can write @interface and @implementation directly in the. m file.
Note that both are written in the. m file, because if the @interface is written in. h, then the methods are public;
B: In addition, we can directly omit the @interface, directly in the. m file to write the method, but still a proposal to write, the benefit is at least read, you can at the beginning of the file in a few lines to tell what is the private method.
This explains why the great God would say that expansion is in fact ubiquitous.
Understand the shallow, if there is no, welcome message.
Further deep understanding of iOS class extension extension