8

Based in part on the advice in this response to a question on SO, I tried replacing /Developer/Library/Xcode/PrivatePlugIns/IDECodeSnippetLibrary.ideplugin with an alias to an exact copy in a Dropbox folder, but doing so caused Xcode 4.2 to crash due to an internal logic error.

I want to sync the snippets on my work and home machine. Right now I'm using Alfred for snippets, but it'd be nice to have Xcode handle the snippets, for convenient tab jumping and intellisense. Has anyone out there attempted something similar?

Community
  • 1
  • 1
Brian Gesiak
  • 6,648
  • 4
  • 35
  • 50

2 Answers2

17

I guess sharing your own (not the system) snippets is fine. Then, try replacing ~/Library/Developer/Xcode/UserData/CodeSnippets with a symbolic link to your shared folder.

Something like: (in Terminal app)

cd ~/Library/Developer/Xcode/UserData
mv CodeSnippets /path/to/shared/folder/
ln -s /path/to/shared/folder/CodeSnippets CodeSnippets

Repeat in any Mac in which you want to access shared snippets.

runmad
  • 14,846
  • 9
  • 99
  • 140
djromero
  • 19,551
  • 4
  • 71
  • 68
  • Sorry it took me so long to try this out. Thanks for the suggestion, but I'm having a little trouble with this. Namely, there is no `CodeSnippets` folder in my `~/Library/Developer/Xcode/UserData`. I tried making one, then symlinking to it like you suggested. I then copypasta-ed `/Developer/Library/Xcode/PrivatePlugIns/IDECodeSnippetLibrary.ideplugin/Contents/Resources/SystemCodeSnippets.codesnippets` into the linked folder and tried changing the name and some of the values, but Xcode doesn't recognize the snippets. I'm using Xcode 4.2, is it possible you're referring to an earlier version? – Brian Gesiak Nov 04 '11 at 18:27
  • 1
    I'm referring to Xcode 4.2 Reset what you've done and add a new custom snippet. Find out where it goes in the filesystem. Then, make the symlink with its containing folder. – djromero Nov 04 '11 at 18:40
  • Ah, I see. I tried making a User-defined code snippet and it did indeed create a snippet within the `~/Library/Developer/Xcode/UserData/CodeSnippets` folder. However, once I made a folder named `CodeSnippets` pointing to another location, Xcode stopped saving snippets to disk altogether. They persist as long as Xcode is running, but on termination Xcode forgets all about any new snippets. Snippets in the symlinked folder are not displayed in the Code Snippet Library and are not being recognized. Sorry if I'm misinterpreting your suggestions again. – Brian Gesiak Nov 04 '11 at 19:09
  • The only explanation I can think of is that you're not following the instructions *exactly* as they appear in my answer. Are you creating the symlink in the right "direction"? – djromero Nov 07 '11 at 15:41
  • I've updated the answer above to include `CodeSnippets` at the end of the last line, which means a new symlink folder is created in `/UserData/` granted the path is setup correctly. – runmad Sep 21 '12 at 18:18
  • It's exactly the same as using a dot, `ln` will get the original directory or file name; but ok, it may be more clear now for unix newbies. – djromero Sep 21 '12 at 21:38
  • I wrote a blog post a while back that might be helpful for anyone reading this: http://runmad.com/blog/2012/09/xcode-code-snippets-and-syncing/ – runmad Apr 15 '13 at 18:31
2

as i do and it work.

simply copy your code snippets in

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

if your didn't made any custom code snippets before then you have to copy whole 'CodeSnippets' dir to path

~/Library/Developer/Xcode/UserData/

now simply close the xcode from activity monitor and start it again you will get new code snippets.

/ use the following code to show hidden file / apply this command one by one in teminal

defaults write com.apple.Finder AppleShowAllFiles TRUE

killall Finder

utkal patel
  • 1,321
  • 1
  • 15
  • 24