Creating our own Code Snippet in Xcode
Posted By : Aditya Kumar Sharma | 30-Mar-2017
Sometimes we need to write same code at several places. So writing it every time can be avoidable by use of Xcode snippets, which allow these common patterns and boilerplate code to be extracted quick and reusable.
Xcode snippets are available in Utilities panel, in the right of our editor. Click { } icon to show Code Snippets Library.
There are two ways to insert a snippet into our code:
1. We can use some of default code snippets into editor by just simple drag and drop.
2. We can create our custom Xcode snippets and use them. Yes we can create our own code snippets. Just follow these simple steps:
- First write down your code snippet in your code editor and select it.
- Now drag and drop the selected code to the code snippet library.
It will be shown like this in code snippet library.
- Now double click this snippet and go to Edit option
and give title to your code snippet, decide the platform and Language for which it should be available. Also, set its Completion scope which is for which method, class implementations, initialisers,.. your code should be available.
Now its ready to use whenever you require it.
Thanks
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Aditya Kumar Sharma
Aditya is a bright iOS developer, have knowledge of objective C, swift, swift 3, JSON, Core data and iPhone development. Apart from that he loves to travel and explore new things.