1. # What are the differences between import and @ class and # include?
Here is a specific description in the previous article.
Add:
@ Class and # import:
@ Class avoid circular references. References are mostly Object class header files.
If. h has imported B. h, then all imported. h files are all associated with B. h. h is modified, and all applications. h files will also be re-compiled. If you can use the pre-declaration instead of import B. h. Instead, use @ class to remove this dependency. B. h is modified. Only. h files may not need to be re-compiled.
2. When declaring class functions in the header file,-(void) print;
The negative sign (-) at the beginning notifies the Objective-C compiler that this method is an instance method. The other unique choice is the positive sign (+), which represents the class method. A class method is a method that performs certain operations on the class itself, such as creating a new instance of the class.
3. import "Fraction. m"
...
Fraction * mFraction;
MFraction = [Fraction alloc];
MFraction = [mFraction init];
...
[MFraction release];
Alloc is the abbreviation of allocate. Because we need to allocate memory storage space for the new object.
When an alloc message is sent to a class, a new instance of the class is obtained, and the returned values (actually allocated Fraction objects) are stored in the variable mFraction, the alloc method ensures that all instance variables of the object are in the initial state. However, this does not mean that the object is properly initialized and can be used. After an object is allocated, you must initialize it:
MFraction = [mFraction init];
Here we use another method that is not compiled by ourselves. The init method is used to initialize instance variables of the class. MFraction sends the init message to the object itself, that is, a special Fraction object needs to be initialized here, so it is not sent to the class, but to an instance of the class. (Andy Note: The init function is very strange. I'm curious about how the init function is implemented in the source code ???)
4. The new method can combine alloc and init operations. Fraction * mFraction = [Fraction new]; new fractions can be allocated and initialized.
5. In NSLog, % x will display a value in hexadecimal format. This value does not contain 0x, and a lower-case character between a and f will be used to represent a hexadecimal number. To use the preceding 0x to display this value, use the format character % # x,
RgbColor = 0xFFEF0D;
NSLog ("Color is % # x \ n", rgbColor );
% E: use scientific notation to display values
% F, displayed in floating point notation
% G. The system determines whether to use the floating point counting or scientific counting to display the floating point value.
6. The OC compiler treats all floating-point numbers as double values by default. If you manually define a float value, add f or F: 12.5f to the number.
7. If long, long, short, unsigned, and signed are placed before int declaration, the declared integer variables have extended Value Domains on some computers. For example, long int factorial. The precision of the long variable is determined by the computer system (depending on the number of digits in the computer)
The long double variable is written as a floating point variable with the letter l or L at the end, 1.233e + 7L
Similarly, in NSLog, % Lf uses floating point notation to display the value of long double, and % Le uses scientific notation to display the same value, % Lg will tell NSLog to choose one between % Lf and % Le.
8. @ synthesize is used to tell the Objective-C compiler to generate a set function method and obtain the Function Method for the instance variables declared in the. h file. (SetXXX (), getXXX ()).
From andy Pan's column