The "iOS app development" series of articles from a more macroscopic point of view, not only limited to specific features, interface implementation, but the combination of NetEase cloud letter IOS Development owner years of experience, from the perspective of how to optimize the existing code, in-depth analysis of how to create more appropriate specifications and frameworks for IOS app development .
Recommended Reading
What's happening with IOS app 2: How to build the right framework
To properly rank code specifications
Everyone understands that software development requires appropriate specifications: code specifications, procedural specifications, process specifications, and so on, to reduce the occurrence of surprises: the least surprising principle. But in the actual implementation will encounter a variety of situations, the biggest problem is: how to identify which specifications are required to enforce, which specifications are recommended for implementation.
The enforcement of the specification results in increased readability and ambiguity of the code, and the downside is obvious: for most of the programmers who have an idea, the rules are too rigid to cause resistance and create unrest. This situation is common in various standard outsourcing companies.
If most of the specifications are set to recommended execution, the specification is easily overlooked without good guidance. There's a lot on the internet OBJC code specifications, such as Apple's own specifications and Google objective-c Style Guide. These specifications generally have only two ratings: recommended and not recommended. And I would recommend dividing the code specification into five levels: mandatory, strongly recommended (but not mandatory), good, acceptable and unacceptable.
Here are just a few examples to illustrate.
In accordance with the Apple standard naming method
The L class name starts with uppercase, and the method and variable names are named by the Hump method. Strongly demanded, this is nothing to say, the Apple System Class library and most of the third-party open source libraries are the same. But in some Apple's sample also saw the use of M prefixes to denote class member variables, these are the legacy code problems, is still acceptable scope, but their own code inside the use of a similar Hungarian naming law is unacceptable.
The L class name is prefixed with at least three characters, and the internal method is prefixed with two underscores. Highly recommended. The above approach minimizes the duplication of names with the System class library: Because Apple claims to retain the right to use all two-bit prefixes, its internal method names are prefixed with an underscore.
L The use of K&r style or Allman style is an acceptable range, but it is highly recommended to keep a form within a file.
L KEEP the code short and unified based on the readability of the code: small class, small method, uniform function return. Small, small methods make it easier for others to focus on class logic, rather than specifics, while reading, and a unified function return can reduce the difficulty of accidental errors and troubleshooting. It is also important to ensure that the code is short and not verbose, and you will often see the following code: if (Count > 1) {return YES;} {return NO;}, I really can't look straight.
Good code/Engineering structure
L Create worksapce for the entire project.
• Categorize resource files according to their responsibilities: each type of resource is stored in a separate directory: Pictures, sounds, profiles, and so on. And the picture can be stored in different subdirectories according to the type: Global type, background map, logo, login and so on.
L A reasonable code structure. The following engineering directory structure is recommended.
Core: Some common mechanism implementation classes in engineering: Unified task management, module management, service management.
General: Common classes and methods, including in-Project Viewcontroller,uitableviewcell base class (base), common category, public UI component (CustomUI), public helper method (Helper ) and the macro definition (Marco).
Model: Common data Models
Sections: Different program units. such as login, settings and so on. It can be divided into sub-directories according to functions: The custom UI component used by the current cell, the management class, the data model and the Viewcontroller, and so on.
Vendors: third-party libraries.
The second article of "IOS app development" will introduce you to what is the right framework, how to build the right framework, and you are welcome to actively express your views and discuss with us.
What's happening with IOS App 1: How to build the right specification