Use code snippets to improve development efficiency and improve code snippet Efficiency

Source: Internet
Author: User

Use code snippets to improve development efficiency and improve code snippet Efficiency

1. What is a code snippet (code snippets)

Code snippet: A memory area used to store code execution.

For example, many development tools have basically integrated this function. You can say that you often use it during coding. Maybe you don't know that you are using the snippet function, for example, if, for, while, and other loop bodies are used when you write code in development tools, they are basically not completely written by yourself, instead, the compiler prompts you to automatically fill in the remaining part of the code. This is the so-called code snippet (code snippets ).

 

Ii. How to Use code snippets in xcode

First, let's talk about how we usually write the UI.

For example, a UILabel

 

Or, for example, a UIButton

 

These are the basic controls that we frequently use when developing the UI. Basically, each page contains many such controls, which means we need to write the same code many times. Some people may say that UILabel can be encapsulated, but in actual development, there are various requirements. Basically, some general attributes need to be assigned values. This topic is not discussed here. Think about this piece of code, even a skilled coder. It may take a minute or two to get a pair of good keyboard players!

 

The topic of code snippets is introduced below.

When we develop a for loop, we only need to enter for, and then the remaining Code only needs to be automatically filled according to the prompts of the compiler. This is very efficient. However, why can't we perform this operation when writing UILabel or UIButton? This can greatly improve the development efficiency when writing the UI. It takes only a few seconds to initialize a UILabel or UIButton. The following describes how to perform the operation.

 

 

Return to Xcode, click Open toolbar on the right in the upper right corner, and click {} in the middle toolbar. You can see the code snippets that comes with the editor below. This is why when we write if or for, the compiler prompts to automatically fill in the subsequent code. These are the code snippets that the compiler has already compiled for us. So we can also Customize various code with high reusability but not completely abstract according to our needs. We can put them here, this allows us to easily and efficiently write the code we want during the development process.

 

 

For example, we often use UILabel, the font color, font size, background color, and other attributes. We can copy this code and press it to the arrow to drag it to the '{}' toolbar mentioned above.

 

The Title is defined here and the name displayed in the toolbar. Another important thing is the definition of Completion into cut in the fourth line. This is the title of the prompt when we write the code. For example, I define it as LabelInit. When I input a Label in the compiler, the compiler prompts me. Let's select the LabelInit code snippet for automatic filling.

 

Click Edit to modify the variables and use <# NSObject #> to automatically change the variable to an NSObject variable.

Well, let's take a look at it. Based on the above definition, let's try it out in Xcode,

When we enter UILabel, the compiler prompts

 

Enter

 

 

Enter UIButton

 

Enter

 

Can this greatly improve the efficiency of UI development.

 

Iii. Summary

In our development process, we often have many identical code blocks that need to be used repeatedly, instead of using code snippets. This will waste a lot of time. When we often pay attention to which code blocks are frequently used, similarly, we can define them as our easy-to-use code snippets. To improve development efficiency, we can spend more time learning other better things online after completing our jobs.

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.