Properties and instance variables for iOS

Source: Internet
Author: User

In fact, @property declares a property, not an instance variable. However, the compiler automatically generates instance variables based on attributes, and corresponding access methods. So the @property has been declared in the interface, it is no longer necessary to declare the instance variable in implementation.

Remember that a property is not an instance variable, but instead generates an instance variable (and the corresponding access method) based on the property. Therefore, the property is named Name, and the name of the instance variable is not. In my environment IOS7+XCODE5, naming rules seem to precede attributes with _

Because the OC midpoint expression represents the calling method, it is not possible to use point operations to access instance variables if there are only instance variables and no corresponding attributes. If a point expression appears on the equals sign = left, the setter method for the property name is called. If the point expression appears on the right, the getter method for the property name is called.

Class is distinguished from the attributes that are added to the category, because only methods can be added to the category, and instance variables cannot be added. It is often seen in iOS code to add attributes to a category, in which case variables are not generated automatically.

Note that anonymous categories (anonymous extensions) can add instance variables, and non-anonymous categories cannot add instance variables, only methods, or properties (which are actually methods).

Import <objc/runtime.h> You can use objc_setassociatedobject this run-time function. You can associate an object with another object. In fact, the implementation of the expansion of a class of memory.

@interfaceUiscrollview (Myrefresh) @property (strong,nonatomic) Defaulttoploadview*Topshowview; @end  @implementationUiscrollview (Myrefresh)Static CharTopshowviewchar;-(Defaulttoploadview *) topshowview{returnObjc_getassociatedobject (Self, &Topshowviewchar); }  -(void) Settopshowview: (Defaulttoploadview *) topshowview{objc_setassociatedobject (self,&topshowviewchar,topshowview,objc_association_retain_nonatomic); }  @end

Properties and instance variables for 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.