Pages

Sunday 7 December 2014

XCode Snippets - How to use?

If you are an iOS developer, you would be spending most of your time with the XCode. One of the most advanced feature of XCode is Code Completion, which is available now with most of the SDKs.

But the sad part is, many SDKs provide the code completion only for their inbuild functions/methods. But in the XCode, we can create our own code completion shortcuts with the help of snippets. Snippets are the small piece of code saved with the XCode, which can be used whenever needed without having to type the same piece of code again and again.

By default the XCode have many code snippets. You can see that in the bottom of the Utilities panel.

Snippets Menu


To create your custom snippet, prepare the piece of code you want, and drag it to the utilities panel. The XCode will open a popup, in which you have to enter the title, description, scope, shortcut. You have to do this only once. Once you finish this, you don't have to type the same piece of code ever. You can make the code appear in the editor either by typing the shortcut or by dragging the snippet to the editor.



The snippets are basic XML and they can be shared to other people. You can find all your snippets in the following path.
/Users/<Your_Name>/Library/Developer/Xcode/UserData/CodeSnippets
Just copy the desired snippet and paste in the same path in another machine.





No comments:

Post a Comment