If you have used Xcode for any length of time, then you probably used a feature called Code Snippets.

Thank you for reading this post, don't forget to subscribe!

Code Snippets are frequently used blocks of code that you can assign a key combination that’ll allow Xcode to automatically type in the code block for you.  You can also backup and share those snippets with other developers.  Unfortunately, this is in a hidden Folder named Library which is apart of the Home Folder.

But first, you have to know where these snippets are stored.

  1. Open Finder.
  2. From the above menu, select the “GO” option and then press the [Option] key.
  3. When the drop down menu appears, there should be a Library option.
  4. Click it. 
  5. The Snippets Folder is in the Library > Developer > Xcode > UserData > CodeSnippets.
  6. Here’s where you can Copy/Paste the Code Snippets Folder to back them up or share them with other Developers.
  7. That’s it. 

Now that you know where the snippets are stored, lets find out how to use them in Xcode.

  1. Open Xcode.
  2. Create a new project OR open an existing project.
  3. When the project loads, highlight the code you wish to save as a Snippet.
  4. Right click on the highlighted code.
  5. A drop down menu appears.
  6. Find and then select Create Code Snippet….
  7. A new window opens.
  8. This window is where you give the snippet a name, description, and assign shortcut combination for the snippet.
  9. Study the window as it is self-explnatory, except for the bottom.
  10. At the Completion field, here’s where you assign the shortcut for the code.  This is up to you.
  11. When finished, click DONE.

Now when ever you type in that shortcut combination and press [ENTER] that code will appear.

About Post Author

(Visited 22 times, 1 visits today)


Advertisement

Like what you've read? Leave a comment below:

This site uses Akismet to reduce spam. Learn how your comment data is processed.

You may have Missed:

Verified by MonsterInsights