Snippet Sync

Recently I got the chance to attend an advanced iOS Training held by a coach from the Big Nerd Ranch. It was no surprise that the training actually was amazing. Every once in a while, the coach showed some details and features in Xcode to the colleagues with a little less experience. One such feature was the code snippets you can create within Xcode and a colleague pointed out a problem with them that I also always had and which is the reason I never use them: If you work on another computer or your Mac had to be reinstalled for some reason, all your code snippets were gone. They don’t sync. It’s a small problem, but somehow it got stuck in my head and I wanted to scratch that itch. Therefore I sat down a little while and created a simple tool that syncs the code snippets created within Xcode to a location you specify, e.g. Dropbox. There are already other tools out there that let you do more things and manage those snippets, but all I wanted was to have them synced to some other place to have a backup.

It’s a command line tool that I run as a LaunchAgent in the background. Whenever I add, remove or modify a code snippet from within Xcode, it gets automatically synced to a backup folder on my OwnCloud. Theoretically I could also add, edit or remove them in this location using a simple text editor and it syncs back to Xcode, but I think I’ll never do that. It is really extremely simple and I’m sure there are lots of issues and things I could add to improve it, but that’s what I needed and so far it works.

Besides scratching that itch, I (re-)learned a lot of things. I didn’t create a command line tool on the Mac in years, let alone in Swift. I can’t remember the last time I manually set up a launch agent. I never used the FSEvent API which is written in C and took me quite a while to use correctly in Swift. So… scratched an itch, built a small tool, learned some stuff. Be it simple as hell, I consider it a small success.

If you are interested, you can find the project and some description on how to use it and how to install the LaunchAgent on my Github profile. If you have a look at it or even use it and find issues or want it to have some other features, feel free to open an issue there and I will check on whether I will add and/or fix it.