How Can One Transfer Xcode 4 Code Snippets from One Machine to Another

XcodeXcode4

Xcode Problem Overview


I've got some user code snippets in my Xcode 4 which I would like to copy to another machine and share with other developers. Is there a way to do so?

Xcode Solutions


Solution 1 - Xcode

Ah found it, they are saved at:

~/Library/Developer/Xcode/UserData/CodeSnippets/

Each one is a plist file. In contrast to Xcode 3 there is now one file per snippet. There is no harm done in renaming them to more useful file names, Xcode will not mind. In fact, my whole CodeSnippets folder is a git repository and many devs share their favorites on github. Mine are at https://github.com/lichtschlag/Xcode-4-Code-Snippets.

Solution 2 - Xcode

As noted by NSSplendid, they're stored in ~/Library/Developer/Xcode/UserData/CodeSnippets/.

You can use Dropbox to sync them; I use this technique to synchronize my key bindings and archives between computers.

Follow these steps:

  1. Quit Xcode.
  2. Move your CodeSnippets directory to your Dropbox. For example, let's say you moved them to ~/Dropbox/CodeSnippets
  3. Let Dropbox upload them.
  4. Pause Dropbox's syncing.
  5. Move them back to where Xcode stores them.
  6. Create a symbolic link into Dropbox: ln -s ~/Library/Developer/Xcode/UserData/CodeSnippets ~/Dropbox/CodeSnippets.
  7. Resume Dropbox syncing.
  8. Relaunch Xcode.

On your other computer:

  1. Quit Xcode.
  2. Let Dropbox download everything, if it hasn't yet.
  3. Pause Dropbox syncing.
  4. Remove your local Xcode user data: rm -R ~/Library/Developer/Xcode/UserData/CodeSnippets.
  5. Move your UserData from Dropbox to Xcode: mv ~/Dropbox/CodeSnippets ~/Library/Developer/Xcode/UserData/CodeSnippets.
  6. Create a symbolic link from your UserData to DropBox: ln -s ~/Library/Developer/Xcode/UserData/CodeSnippets ~/Dropbox/CodeSnippets.
  7. Resume Dropbox syncing.
  8. Relaunch Xcode.

The convolutions are necessary because Xcode will not follow a symlink, but Dropbox will. Dropbox will treat that symlink exactly as if the directory was actually there.

This is not perfect; you will probably have to quit Xcode to have it recognize new snippets.

I sync my entire UserData directory, which gets me synchronized key bindings, named tabs, font & color schemes and code snippets. To do this, move and ln ~/Library/Developer/Xcode/UserData instead.

Solution 3 - Xcode

I made a Xcode plugin for synchronizing snippets with a git repository.

With it, you can share snippets on different computers and even among a team.

The ACCodeSnippetRepository plugin is available on Alcatraz and Github.

Solution 4 - Xcode

They are located at ~/Library/Developer/Xcode/UserData/CodeSnippets/

It's good practice use version control for that if those snippets are meaningful to you. Than it's sufficient to do periodic commits and push changes to remote branch.

Solution 5 - Xcode

I'm not gonna give you exact answer, but rather a guideline: code blocks, completions, project/file templates (from File -> New...) are held in separate files probably somewhere in [~]/Library/Application Support/Developer/Shared or somewhere else. So my final point is - search through files for snippets or their titles and I am pretty sure you will find a location where all user made code snippets are stored.

If that's the case - then just copy over those files to other machine, restart Xcode there and you should be good.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKristopher JohnsonView Question on Stackoverflow
Solution 1 - XcodeNSSplendidView Answer on Stackoverflow
Solution 2 - XcodeSteven FisherView Answer on Stackoverflow
Solution 3 - XcodeacoomansView Answer on Stackoverflow
Solution 4 - XcodeLeszek ZarnaView Answer on Stackoverflow
Solution 5 - XcodeEimantasView Answer on Stackoverflow