Will Larche
Will Larche

Reputation: 3149

Can you sort the code snippets table?

In Xcode 5, can you sort the list of code snippets?

I've made one of my own and it's down at the bottom. I'd rather have it be up at the top.

Where it currently is.

Upvotes: 3

Views: 305

Answers (1)

Tommie C.
Tommie C.

Reputation: 13181

One cannot automatically sort the snippets. One can go into the snippet file and reorder the snippets. System snippets are always presented first so to move a user snippet to the top one would copy the data for the snippet between the dictionary tags (....) to the top of the system snippets.

How to do it

Be advised that it is likely one would lose the ordered snippets when Xcode is upgraded so this should be considered but here is the way to force the issue:

  • Backup the affected system snippet file (/Applications/Xcode.app/Contents/PlugIns/IDECodeSnippetLibrary.ideplugin/Contents/Resources/SystemCodeSnippets.codesnippets) for safety
  • User snippets are stored as a series of xml files located in the following directory ~/Library/Developer/Xcode/UserData/CodeSnippets/
  • Create a user snippet
  • Go to the user snippets folder and open the file just created with a text editor (these are just xml files so TextEdit, TextMate, et al will do)
  • Copy the user snippet between the ... tags
  • Paste the user snippet data into the system snippet data at the top

Why you should avoid doing it

  • Changes will likely be lost when Xcode is updated

  • You can and should create a shortcut that will allow you to type the entire snippet into code easily

  • Your title of the snippet is also searchable (making the snippets easy to find)

What is the alternative

I suggest you open an enhancement request at http://bugreport.apple.com to ask Apple to make a sort option available.

Upvotes: 2

Related Questions