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

 

 

About Author

Author Image
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.

Request for Proposal

Name is required

Comment is required

Sending message..