Further deep understanding of iOS class extension extension

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.