In Objective-c, defining a class requires two parts: the first is the interface (interface), and the second is the implementation (implementation). interface to the interface file, and the implementation corresponds to the implementation file. The interface file contains the declaration of the class, the member variable (member variable), and the method. interface files are usually. h
An implementation file is usually a. m file. The method that is declared in the interface needs to be implemented by x code in the. m file.
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.
If you have been in contact with C + + before, the member variable (member Varialbe) is certainly not unfamiliar. Today, you see this familiar term, you will feel objective-c not as difficult as you think.
At this point, ears rang the slogan: The original formula, or the familiar taste. HA:)
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.
Class: Class (Description/Template ForAnObject)
Example: Instance (manifestation of a class)
News: Message (Sent toObjectTo make It act)
Method: Method (Code invokedByAMessage Instance variable ( Object-specific storage)
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.
Strictly speaking, the int count in; is a member variable. and NSString * name; 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, theID is equivalent to (void *).
so ID data should belong to the instance variable.
OBJECTIVE-C Basic syntax: The difference between an instance variable and a member variable