Oc uses a dynamically bound message structure, that is, object types are checked at run time. It is up to the runtime environment, not the compiler, to decide what code to execute after receiving a message.


Use @class instead. This reduces coupling between classes, reduces compile time, and prevents loops from being introduced. 2. Sometimes forward declarations are not possible, such as declaring that a class follows a protocol. In this case, try to move the statement “this class follows a protocol” into the class-Continuation class. If not, put the protocol in a separate header file and import it.


Create string, numeric, array, dictionary. Use literal syntax when possible, which is more concise than the normal method of creating such objects. NSArray and NSDictionary, in particular, are safer with literal syntax, making it easier to throw errors where they go wrong. 2. An array subscript or dictionary keylock should be accessed by a subscript operation.


The static modifier means that the variable is visible only in the compilation unit where it was defined. When the compiler does not receive a compilation unit, it outputs an “object file.” In the context of OC, the term “compilation unit” usually refers to the implementation file (.m) for each class. When you add a declared variable without adding static, the compiler creates an “external symbol” for it. If a variable with the same name is declared in another compilation unit, the compiler throws an error message. If a variable is declared static and const, the compiler does not create symbols at all. Instead, like the #define preprocessor, the compiler replaces all encountered variables with constant values. Notice where const is in the statement. Should precede the variable name, meaning that the variable pointer is invariant. 2. Do not define constants with preprocessing instructions. Constants thus defined do not contain type information, and the compiler simply performs a look-and-replace rub at compile time. Even if someone redefines a constant value, the compiler will not generate a warning message, which will result in inconsistent constant values in the application. 3. Use static const in the implementation file to define constants visible only within the compilation unit. Because such constants are not in the global symbol table, there is no need to prefix their names. 4. Use extern in header files to declare global constants and define their values in related implementation files. Such constants appear in the global symbol table, so their names should be separated and usually prefixed by the name of the class associated with them.


Enumerations cannot be declared without specifying the underlying data type, because the compiler does not know the size of the underlying data type, so it does not know how much space to allocate to the variable when using the enumeration. 2. The NS_OPTIONS macro is defined differently depending on whether you want to compile your code in c++ mode. If not compiled in c++, it expands in the same way as NS_ENUM. If compiled in C++, the expanded code looks slightly different. The reason is that C++ compiled mode handles two enumerated values differently than non-c ++ mode when using bitwise or operations. Enumeration values as options often need to be combined with bitwise or operations. When operating on two enumerated values with an or operation, C++ assumes that the resulting data type should be the underlying data type of American TV series, which is called NSUInteger. And C++ does not allow the “implicit conversion” of this underlying type to the thunderplay type itself. You need to convert the display of bitwise or operation results. Therefore, the NS_IPTIONS macro should be defined in C++ mode in a different way to eliminate the type conversion operation. Because of this, enumerations where an activity needs to be combined by bits or operations should be defined using NS_OPTIONS. If American dramas do not need to be combined, use NS_ENUM to define them. 3. Do not implement the default branch when using enumeration with switch, because when the enumeration option is added later, if there is no default branch, there will be a message indicating that there is no default branch. If there is a default branch, this message will not be displayed. Enumeration classes should be used to represent the state of the state machine, the options passed to the method, and the equivalence of the state, giving the values easy-to-understand names.


Article 6:1. If properties are used, the compiler automatically accesses the methods needed for those properties, a process called “automatic composition.” This process is performed by the compiler at compile time, so the source code for these “composite methods” is not visible at compile time. 2. In concurrent programming, an operation is “atomic”, or “atomicity”, if it is holistic — that is, if the interim results of the intermediate steps are not visible to the rest of the system, but the results before and after the operation are visible. See: http://en.wikipedia.org/wiki/Atomicity_ (programming) 3, nsstrings generally use copy to protect its packaging operations, because the setting method is passed to the new value may point to an NSMutableString class instance. If the string is not copied at this point, the value of the string may be changed without the object’s knowledge after the property is set. And if you override setter methods, you need to ensure that they have the properties declared by the related properties in the method. For example, if a property is declared as copy, the associated object should be copied in setter methods, otherwise it will dance the user of the property. Also, failure to follow this convention can bug your program. 4. The difference between Atomic and nonatomic: Atomic methods use locking mechanisms to ensure that their operations are atomic. That is, if two threads read and write the same attribute, the valid attribute value can always be understood at any time. Without locking (or using nonatomic semantics), one thread is rewriting a property and another thread may pop in and read the value of the property that has not been modified. When this happens, the thread may read the property values incorrectly. However, in actual iOS development, you will find that all properties are declared as nonatomic. The historical reason for this is that using synchronization locks in iOS is expensive and can cause performance problems. In general, attributes are not required to be “atomic” because they do not guarantee “thread safety” and a deeper locking mechanism is required for thread-safe operations. For example, if a thread reads a property value several times in a row and another thread overwrites the value, different property values will be monitored even if the property is declared atomic. As a result, nonatomic properties are commonly used when developing iOS applications. However, when developing MAC OS X programs, there are usually no performance bottlenecks in using atomic attributes. 5. Use nonatomic properties when developing iOS applications because atomic properties can seriously affect performance. 6. When setting the instance variable corresponding to the attribute lock, be sure to follow the semantics of the attribute lock declaration.