IOS code specification document and ios code specification

Source: Internet
Author: User

IOS code specification document and ios code specification

File naming rules:

1. The project uses the class prefix ZY.

2. Classification naming + ZYExtension is used in the end. For example, NSDictionary + ZYExtension. h. Common Classification definitions are embedded and document comments are written. If there are many internal functional classification methods, you can consider naming them by function.

3. The model file can be named by the server interface name or field name, and the view, viewModel, and controller files can be named by function.

4. name the cut chart: home_menu_chat,-> module _ function _ specific name. The cut chart name is very important. This can be communicated with the art, so that they can name it directly and give it to us, which can greatly improve the development efficiency, do not use Chinese.

Code specification:

1. The classification method starts with zy _ and can be differentiated from the system or third-party framework method.

2. Global strings or basic data types should be defined as constants rather than macros. Static modification is only used inside a file and should not be exposed to. H files.

3. macro definitions start with ZY _ and are all uppercase and separated.

4. Internal class methods are divided by function and use # pragma mark <# xxxx #> in a unified manner.

5. If there are many method parameters, use line breaks to align the parameters to improve readability.

6. document comments are recommended for method property comments. You can download the VVDocument plug-in.

7. To define member variables, add underscores (_) According to apple specifications.

8. Try to use lazy loading to create controls and properties so that they can be created when they are used. Note: Do not directly use the name of the underline member variable to access the file created by lazy loading. You should use the get method to access the file.

9. block callback can be used as much as possible to increase the code polymerization degree. However, we recommend that you use weak references inside the block to pay attention to circular references.

10. copy is required for declaring string attributes, and weak is used for proxy, but use as few proxies as possible, making block callback more convenient.

11. Pay attention to the names of methods, attributes, and member variables.

12. You 'd better put the Destructor void dealloc at the top of the class. At first glance, you can see this method to see whether to clear resources.

13. The code of a single method should not exceed 100 lines, and the code of a single file should not exceed 800 lines. If the Code exceeds lines, you can consider refactoring optimization.

14. For the same logic method or multiple methods used in multiple places, you can prioritize classification, and then select a tool method class.

15. The control name must be added to the definition control or controller, for example, an imageView-> UIImageView * iconView. Do not directly use the UIImageView * icon.

16. Determine whether YES/NO/nil adopts this method.

17. We recommend that you use a custom UIImage classification method to load images. For example, [UIImage zy_imageNamed: @ "]. It can be intercepted by the change method and may be used by skin replacement.

18. All network requests start with request. For example, if the returned result is block and corresponding to a data model, and error. If the error value exists, the request is incorrect. We recommend that you use a third-party framework: YYModel-> dictionary-to-model framework, which provides better performance than the mainstream frameworks and is easy to use. YYCategories-> provides some common classification methods to greatly accelerate development efficiency. YYWebImage-> loads the network image frame, which can be animated and easier to use than SDWebImage. MJRefresh-> pull-down refresh control AFNetworking-> network request Pop-> facebook animation framework SVProgressHUD-> HUD prompt, a singleton class, global sharing, there is no need to repeatedly create a Masonry-> Automatic Layout Framework Realm-> recently popular database framework. It is said that the performance is seckilling coreData and sqlite, and the learning cost is very low. ReactiveCocoa-> function responsive programming framework.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.