1, Objective-c for C language has added object-oriented features, is its superset. Objective-c uses a dynamically bound message structure, which means that the object type is checked at run time. What code should be executed after accepting a message is determined by the run-time environment, not the compiler.
Understanding the core concepts of C language helps to write good objective-c programs, especially to master memory models and pointers.
2. Do not introduce a header file unless it is indeed necessary. In general, you should use forward declarations in the header file of a class to refer to other classes and introduce a header file in the implementation file. This minimizes the coupling between classes.
It is sometimes impossible to use forward declarations, such as declaring a class to follow a protocol. In this case, try to move this declaration of "Certain class following an agreement" to the "Class-continuation classification". If not, put the protocol in a single header file and introduce it.
3. You should use literal syntax to create strings, numbers, arrays, dictionaries. This is more concise than the usual method of creating such objects.
The element that corresponds to the key in the array subscript or dictionary should be accessed by subscript operation.
An array or dictionary created in literal language that throws an exception if there is nil in the value. It is important to ensure that the value does not contain nil.
4. Do not define constants with preprocessing directives. The constants defined in this way do not contain type information, and the compiler simply performs a find and replace operation on this basis before compiling. Even if a constant value is redefined, the compiler does not produce a warning message, which causes the constant values in the program to be inconsistent.
Use the static const in the implementation file to define constants that are visible only within the compilation unit. Because such constants are not in the global symbol table, you do not need to prefix their names.
Use extern in the header file to declare global constants and define their values in the relevant implementation file. This constant is to appear in the global symbol table, so its name should be separated, usually prefixed with the class name associated with it.
5. Enumeration should be used to indicate the state of the state machine, the options passed to the method, and the status code equivalent, giving these values an understandable name.
If the option passed to a method is expressed as an enumeration type, and multiple options can be used simultaneously, then each option is defined as a power of 2 to be combined by a bitwise OR operation.
Use Ns_enum and Ns_options macros to define the enumeration type and indicate its underlying data type. Doing so ensures that the enumeration is implemented using the underlying data type chosen by the developer, rather than using the type chosen by the compiler.
Do not implement the default branch in a switch statement that handles enumeration types. In this case, after the new enumeration is added, the compiler will prompt the developer: The switch statement does not handle all enumerations.
One of the 52 Essentials of iOS development