[Study Notes-Objective-C] Chapter 10 variables and Data Types in Objective-C Programming version 6th
Part 1. instance variables and attributesThe current trend is to use (_) as the start character of the instance variable name. In the implementation part, explicitly declare that the instance variable is private
ThereforeNoIn the subclass, you can directly obtain the instance variable value by name. OnlyInherited access methodObtains the value of an instance variable. Not Required@synthesize
Command to generate an access method, as long as it is declared in the attribute.Part 2. Global VariablesLowercase g is the first letter of the global variable:int gMoveNumber = 1;
Is also an external variable. External variable: accessed by any other method or function to access and change the value: Add a keywordextern
:extern int gMoveNumber;
Addextern
Is the declaration of the variable, not the definition. The Declaration will not cause variable storage space allocation, but will be defined. If you use many methods to access global variables, perform the following operations at the beginning of the file:extern
If there are only a few accesses, it is best to separate them within each method.extern
StatementPart 3. Static variablesDefined as a global variable, but not an external variable: Except for methods in a specific class, no other method needs to access this specific variable:static int gGlobalVar = 0;
: Methods or functions after this statement can access the value of gGlobalVar, but not methods and functions in other files.Part 4. enumeration data typeEnumeration type: provides a method to match an integer with a symbolic name.
To change the value of this integer, you can only change it in the place where the enumeration is defined. Example:enum direction {up, down, left = 10, right};
The addition of element sequence, integer + 1, and so on.Part 5. typedef statement
Typedef: change the data type name.
typedef int Counter;Counter j,n;
Added the readability of variable definitions and clearly showed the purpose of using these variables in the program.
Part 6. Data Type Conversion
Calculation of different data types:
If one of the operations is
long double
,
double
,
float
Type, the result is also
long double
,
double
,
float
Type. If one of the operands is Bool, char, short int, bit field, or enumeration type, all are converted to int type. If one of the operations is
long long int
,
long int
Type, and the other operand is converted
long long int
,
long int
Type, the result is also
long long int
,
long int
Type. Both operands are
int
Type, the result is also
int
Type.