Code snippet management

About this article:

1. Introduction to code snippets

2. Define your own code snippets

3. Use Git to manage code snippets and set up cloud warehouses without device restrictions

4. Introduce other code management tools, such as Dash


 

1. Introduction to code snippets

The code snippet function has been provided since Xcode 4.0. Code snippets are templates of some codes. For some common programming patterns, Xcode abstracts these codes into templates and puts them into code snippets. When using them, you only need to type out the set keys to fill in the contents of the templates. into the code. ,

Let’s introduce so much. The benefit is definitely to improve the efficiency of coding. Whoever uses it knows.

2. Define your own code snippets

It's quite simple, just select all the code that needs to be used as code snippets, and then drag it to the code snippet area in the lower right corner of Xcode. Then the edit interface will come out and make some settings. The English language that the interface hurts is very simple, so I won't introduce it here.

For the part that needs to be replaced when used later, use the format of <#replaced content#> . (hint: the # in the back is reserved for the last knock , otherwise you will~)

3. Use Git to manage code snippets and set up cloud warehouses without device restrictions

Xcode code snippets are stored in

~/Library/Developer/Xcode/UserData/CodeSnippets

Therefore, this directory can be set as a Git repository, and then Github can be used as a cloud repository.

Going through the above path, you can see that it is not a file type that we are familiar with, so to import the code snippets on Git into Xcode later requires the help of some scripting languages . There are also more self-documents in this area, Baidu [How to import code snippets in Xcode]. Here is the Github address of the code snippet of "Tang Qiao", you can imitate and create it.

https://github.com/tangqiaoboy/Xcode_tool

4. Introduce other code management tools, such as Dash

Although Dash's code snippets feature is not as convenient as Xcode's inheritance, Dash can be integrated with any compiler and can manage any text snippet .

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325081974&siteId=291194637
Recommended