Code Snippets for Xcode development tips (snippet)Wangzz Original address: http://blog.csdn.net/wzzvictory/article/details/12163939 reprint Please specify the source if you feel that the article is helpful, Please leave a message or follow the public account wangzzstrive to support me, thank you! I. What is a code snippet when you enter Dowhile in Xcode and return to enter, Xcode appears with the hint code shown: This is the code snippet, which is designed to enable programmers to enter frequently used code snippets as quickly as possible to improve programming efficiency. This feature was introduced from Xcode4. The location in Xcode is as follows: There is a lot of code snippets from Xcode, and the dowhile in the example above is one of them. How to customize code snippets because of the difference between the project, the language used, or the coding habit, different programmers are accustomed to using snippets of code that are not the same, and there is a need for custom code snippets, which is good enough for Xcode to support this feature. The definition of @property attribute is a common feature in Cocoa program development, as an example of how to customize code snippets. 1, write the code fragment in the declaration of the @property property where the following statement:
[CPP]View Plaincopy
- @property (nonatomic, retain) < #type #> < #name #>;
Here < #type #> and < #name what the effect can be seen in the later use effect. 2, new code snippet Select the above statement, with the left mouse button to the code snippet indicated in the area of Xcode, a new code snippet 3, edit the code snippet after the 2nd step, release the left mouse button, will pop up the code Snippet editing window, As shown: The top-to-bottom meanings in the diagram are: ①title the title of the code fragment ②summary the description of the code snippet ③platform the platform that can use the code snippet, Ios/os x/ All three options ④language in which languages you can use the snippet ⑤completion shortcut snippet shortcuts, such as the dowhile used at the beginning of this article, where Set the shortcut for the property setting to Property⑥completion scopes you can use the current code snippet in which files, such as all locations, the header file is medium, and of course you can add multiple supported locations. The last large empty area is a preview of the effect on the snippet. When everything is set up, click the Done button in the lower right corner of the menu and the new job is finished. Third, the use of code snippets in two ways to use our custom code snippet, or the @property attribute code snippet just defined as an example: 1, in the appropriate location (because the definition of code snippets can be set to use the platform, language, use of files and other restrictions), input property2, To find the one we just defined in the Code Snippet section, drag the snippet to the right position using either of the two methods above to see the effect shown: here, you'll notice that the < #type #> and < #name written when you define the snippet > has played a role in it! Iv. Backup of code snippets the code snippet in Xcode is placed by default in the following directory:
[Java]View Plaincopy
- ~/library/developer/xcode/userdata/codesnippets
We can back up the code snippets in the catalog, or they can be copied directly to use on different computers, so there is no pressure for collaboration among multiple computers.
Set Xcode to generate code snippets automatically (GO)