iOS categories (category) You cannot add member variables but you can add properties to an issue

Source: Internet
Author: User

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

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.