Categories do not need to introduce a bunch of online (using Objective-c's dynamic runtime allocation mechanism, you can add new methods to existing classes, this way of adding new methods to existing classes is called Category catagory, he can add new methods to any class, including those without source code).
This blog mainly wants to discuss questions about categories that cannot add member variables.
The diagram is a uiimageview category I created, named Network, and I gave an error when adding an instance variable View1 to the category (the instance variable is one of the member variables, the instance variable should be a variable defined by the class), meaning that the instance variable cannot be placed in the category. But Localimage is a property I created, without an error. However, this localimage is not available in @implement Uiimageview (Network) in. m files and can only be used in @implement Uiimageview.
Figure 1:
The above paragraph may not understand, why not use it? Look at the picture below (Figure 2), I called this method in the controller, but the print self.localimage error, said "Localimage" This property is not on the Uiimageview type of object, a little difficult to understand. But if you uncomment the following Set/get method and run through it again (Figure 3) and find Self.localimage = nil, the description category does not automatically generate the Get/set method for the property. (_localimage cannot be used, stating that the attribute is declared without generating a member variable at the beginning of _)
Figure 2:
Figure 3:
Figure 4: Direct error, so the added attribute cannot be used in @implementaion Uiimageview (Network)
iOS categories (category) You cannot add member variables but you can add properties to an issue