Effective Objective-C 2 reading notes (1)

First, understand the origin of Objective-C

1.Objective-C adds object-oriented features based on the C language.
2.Objective-C evolved from Smalltalk, using the message structure.
3.Objective-C is a dynamic language that always looks for running methods at run time, and the program’s operations are determined by the running environment. The
4. pairs are allocated in the heap, and the variables pointing to the object are stored in the stack.

The second, in the class header file, minimize the introduction of other header files

1. in the header file, use the @Class reference in advance to introduce other header files.
2. uses @import in the implementation file to introduce other header files, avoiding circular reference header files, and reducing compile time.
3. follows the delegate in the implementation file class-continu.
4., if you can’t declare protocl in the header file, write a.H file individually, declare protocl.

Third, more literal grammar, less use of the equivalent method

1. numerical | non literal literal
| literal |
|NSNumber – |: someNumber = [NSNumber numberWithInt:1]; |NSNumber someNumber = @1;
2. | literal array
| non literal | literal |
|NSNumber – |: Animals = [NSArray arrayWithObjects:@ @ dog “,” cat “” @ “mouse”, “badger”, @ nil]; |NSNumber someNumber @[@ = “cat”, “dog”, @ @ @ “mouse”, “badger”];
3. | literal dictionary

1. literal syntax, in addition to strings, the created objects must belong to the Foundation framework.
2. uses literal syntax to create strings, arrays, and dictionary objects that are immutable.

Fourth, the use of type constants, less #define pretreatment instructions

1. preprocessing defines constants that have no type information.
2. pretreatment process will encounter all defined keywords are replaced with the assigned value, so if the instructions in a header file, if the reference to the header file, then all the key words will be replaced.
constant type:
1., if you do not intend to publish a constant, define the constant in the implementation file. The
2. variable must be declared with both static and const, and if you try to modify the variables modified by const, the compiler will make a mistake. The static modifier means that the variable is visible only in the compilation unit of this variable.

Fifth, use enumeration to represent status, options, status codes

Typedef NS_ENUM (NSUinteger, EOCConectionState) {EOCConnectionStateDisconnected, EOCConnectionStateConnecting}, EOCConnectionStateConnected; typedef NS_OPTIONS (NSUInteger, EOCPermittedDirection) {EOCPermittedDirectionUp < = 1; < 0, EOCPermittedDirectionDown = 1 < < 1; EOCPermittedDirectionLeft = 1, < < 2, EOCPermittedDirectionRight = 1 < < 3.;};