How to Create a Code Snippet in Xcode
In Xcode, a code snippet is a reusable block of code that you can quickly insert into your project. Although Xcode provides a collection of predefined snippets, you can also create your own to streamline your workflow.
Your custom Snippets can be quickly accessed using the code completion feature in Xcode by typing a shortcut.
Creating a Custom Code Snippet
Begin by highlighting the code you want to convert into a snippet and then double-clicking to bring up the menu.
Select Create Code Snippet.
Add the Summary and enter the characters you want to use to auto-complete your snippet.
My code snippet adds a section header before an extension code block and I’ve used the character Ext for the auto-completion.
Now, whenever I need to create a new section header for Swift Extensions, I just type Ext into Xcode and press enter to auto-complete.
How neat is that?
And the best part is that it’s not just code snippets, you can also use it to create templates.
Happy Coding!
i.xo