A unified code block and iOS comments are attached to the ios project annotation specification.

Source: Internet
Author: User

A unified code block and iOS comments are attached to the ios project annotation specification.

Code comments are often ignored, making it difficult to maintain code later. We are preparing to develop a standardized annotation system before the XX Project starts, so that we can quickly get started even if maintenance personnel change.

1. Attribute comments

The format of the/** comment */document comment used for property annotation. The advantage of this annotation compared with // annotation is that this attribute can display Chinese annotations below the smart prompt when it is referenced later.

If you do not see this article in Dong baoran blog, click to view the original article.

For example:

/** Response rate */@ property (nonatomic, strong) MTPoiCompareM * replyRate;/** reply speed */@ property (nonatomic, strong) MTPoiCompareM * replySpeed;


@ Property (nonatomic, copy) NSString * name; @ property (nonatomic, assign) float avgScore; @ property (nonatomic, assign) int dealid; @ property (nonatomic, assign) float price; @ property (nonatomic, assign) int feedbackNum;

  


① Annotations must be added for attributes that cannot be quickly and clearly understood for this purpose through the attribute name. For example, who is the index? However, annotations must be added for attributes with the following features:

② There may be 0, 1, or 2 status-like tags that need to be written together with comments in several cases.

③ The attribute name cannot be expressed clearly.

The above features correspond to the following code one by one:

/** Subscript of the top category */@ property (nonatomic, assign) int index;/** project type 1: Group Buying 2: coupon */@ property (nonatomic, assign) int type;/** industry average data */@ property (nonatomic, copy) NSString * cateValue;

  


Here we will insert the steps for introducing code blocks. Here, the uniform attribute annotation code block is/** <# comment #> */The shortcut key is xx

 

2. Steps for introducing code blocks

1. Copy the orange part to any position in the project. The part is automatically scaled into a block.

Then, drag these code blocks to the bottom right corner.

After you drag it into the folder, the setting box is displayed and set as required.

Click done, and the code block will exist in Xcode.

The advantage of using a code block is that you can press the shortcut key and press enter in the project to immediately display your preset code. You can press the tab key to quickly switch to small pieces for writing.

 

3. method set comment

The system has a built-in method set annotation code block.

However, there is no separator line. If you want to add a separator line, you need to add mark-to keep up with the comment. This is a little troublesome.

After use, you can achieve the following results:

Now let's unify the code block.

# Pragma mark-****************** <# enter comments #> the shortcut key is mark

* ** Is used in the middle to avoid overlap with the following comments before viewing.

 

The method set of the data source methods or proxy methods of all classes must be separated by a line of method set annotations. (The Code requires that several proxy methods of a class be written together)

 

4. Normal comment

The logic in a certain part of the project may be complicated or the code of the core idea. In this case, some annotations should be added as annotations, which is also conducive to self-maintenance of the Code, so that others can take over the code later.

For example:

Now let's unify the code block.

// ------ <# Single line comment #> the shortcut key is gg

 

5. Priority comment

This key annotation can be customized. The code block for my key annotation is as follows. We recommend that you unify it for ease of viewing.

// $ The shortcut key is dd

It is usually written in a large project where you often need to jump over and modify it. The usage is to press dd and press enter after this line of code.

 

When you need to find them, you only need to search for the project to quickly locate them.

You can also set the priority $ or $ here. We recommend that you mark the key or common exceptions without being stingy.

If you do not see this article in Dong baoran blog, click to view the original article. Indicate the source for reprinting.

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.