Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

xcode

xcode4

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?

like image 619
Kristopher Johnson Avatar asked Mar 10 '11 14:03

Kristopher Johnson


People also ask

Where are Xcode snippets stored?

Code snippets are stored in your ~/Library/Developer/Xcode/UserData/CodeSnippets directory. To share your code snippets, simply copy them from this directory. Each code snippet file is a standalone plist file with a universally unique identifier (UUID) as the file name followed by .

What is snippet in Swift?

Paul Hudson @twostraws. SE-0356 introduces the concept of snippets, which are designed to fill a small but important documentation gap for projects: sample code bigger than simple API documentation, but smaller than an example project, designed to show off one specific thing in your project.


2 Answers

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.

like image 89
NSSplendid Avatar answered Dec 02 '22 15:12

NSSplendid


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.

like image 38
Steven Fisher Avatar answered Dec 02 '22 17:12

Steven Fisher