OC instance variable (Instance var) and member variable (member Var) difference

Source: Internet
Author: User

Absrtact: Objective-c introduces the concept of " instance variable" , but at the same time, the sound of "member variable" is often seen. What is the difference between an instance variable and a member variable?

when viewing Apple's official documentation today (see below). Https://developer.apple.com/library/mac/referencelibrary/GettingStarted/Learning_Objective-C_A_Primer /index.html

A new noun was found: the member variable (member variable). It is novel because it is called an instance variable (instance variable). Remember, when first contact objective-c, see instance variable this noun, feel very novel. We also try to compare the instance variables with the member variables and study their differences. From this diagram below, it can be concluded that the instance variables I saw earlier, essentially, are member variables. For iOS beginners, a novel noun can easily make people think too much.

MyClass *math=[[myclass alloc] init];in the figure "Member Variable declarations", literally means: "Member variable Declaration". It appears that the variable declared in {} is a member variable. So what does an instance variable mean? since OC is expressed in English, it may be useful to look up the original meaning in English. classes: Class (Description/template for a object)
Example: Instance (Manifestation of a Class)
MSG: Message (Sent to object to make it Act)
Methods: Method (code invoked by a Message)
instance variable: Instance Variable (object-specific storage) member variable (member Varialbe)Superclass/Sub-class: Superclass/subclass (Inheritance)
Protocol: Protocol (non-class-specific methods) from the English explanation given, it can be seen that the instance (Instance) is for class. An instance is a declaration of a class, whereby an instance variable (Instance Variable) refers to an object declared by a class. strictly speaking, int count in, is a member variable. and NSString * name; is an instance variable, and math is an instance variable.
should ID data belong to a member variable or an instance variable? Because the ID is an OC-specific type. In essence, the ID is equivalent to (void *). so ID data should belong to the instance variable.

OC instance variable (Instance var) and member variable (member Var) difference

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.