Use of categories in iOS

Source: Internet
Author: User

Three major functions of the category
1. Add methods to existing classes, you can increase the object method, or you can add static methods.

If the added method is a method of this kind, then this method may overwrite the original method or it may not overwrite it.

Categories can only increase the methods of existing classes and cannot increase the properties of the class


2. Declaring a private method

You can use categories to implement the declaration of a private method (a method that you do not want to leak in the header file) to prevent the compiler from warning @interface categorytestviewcontroller (privatemethods)-(void) Testprivatemethod, @end @implementation Categorytestviewcontroller (privatemethods)-(void) testprivatemethod{} @end


3. The same class of code, scattered into different files, such as Nsindexpath, a part of the method is written in the Uitableview.h

Use of categories in iOS

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.