About iOS object-c categories-static methods for category categories and private variables, protocol protocol

Source: Internet
Author: User

about iOS object-c categories-static methods for category categories and private variables, protocol protocol2014-02-18 19:57 315 People read Comments (0) favorite reports 1.category, the method of overwriting the original class, even if does not refer to the category header file, can also overwrite, Respondstoselector: Method can also respond.
2.category, there can be no private variables, but there can be @property declaration, the property declaration only declares the class's Set,get method (need to reference the category header file), But the category implementation of the M file does not generate these two methods, so you use Self.xxx, will hang out, error: There is no Get/set method.
You can't declare it in the M file of category @synthesize,
In other words, there is a declaration, no implementation.
3.category static method, can be used,
Even if not declared, but directly to achieve,
When called (no reference to the category H file), there will be a warning, but it will still execute.
Call, can only use the class name, with the object, will hang out.


About Protocol @protocol
A protocol cannot be instantiated, so it cannot have an instance variable (or a private variable), but it can have a @property declaration, which simply tells others that there are set,get methods in the protocol.
Note: Try not to declare in @protocol with @property, it is easy to get out of the wrong, especially when output attributes.
If you want to use @property, you can refer to Uitextinputtraits, the official agreement is @property

The protocol can have static functions. This is a bit of a conflict with the Java interface, the interface can not have static functions.
The static constants cannot be defined in the Protocol, as is the case when the file is referenced, but the compilation error


The informal agreement is a classification, category, for the category of the root category.
For example @interface nsobject (category name)
But in object-2.0, the informal agreement has been replaced with @optional.

About iOS object-c categories-static methods for category categories and private variables, protocol protocol

Related Article

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.