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