ACCodeSnippetRepositoryPlugin is a Xcode plugin for seemless synchronization of snippets with a git repository.
The snippets are synchronized as human-readable text (and not an obscure .codesnippet plist).
If you want to know more about snippets in Xcode, I recommend reading Xcode Snippets on NSHipster.
Want to try the plugin with an existing public repository? Try acoomans or mattt's snippets.
Build the project to install the plugin. The plugin is installed in /Library/Application Support/Developer/Shared/Xcode/Plug-ins/ACCodeSnippetRepository.xcplugin
.
Restart Xcode for the plugin to be activated.
Alternatively, install through Alcatraz plugin manager.
There should be a Plug-ins
item in the xcode menu:
First configure the plugin by forking a remote repository:
When you fork, all snippets from the repository (with the right format, see below Format) will be imported in Xcode. Your existing snippets, that do not belong to any repository yet, will not be affected.
After forking, you will given the choice to import (user) snippets from Xcode to the repository.
Also, you can remove the system snippets if you don't use them.
In case of any problem (see below, Bugs and limitations), you can go to the user snippets folder and backup your user snippets. Note that user snippets are automatically backed up before any fork.
Use snippets like you always do in Xcode. Snippets are automatically added/edited/removed and pushed to the git repository.
The snippets are text files with a .m file extension, in the following format:
If your snippet does not contain any header, the header will be added, committed and pushed when imported.
Note: do not remove the Xcode-related information as they are needed for synchronization.
Note: if you manually create a snippet by copying an existing one, change or remove the IDECodeSnippetIdentifier as Xcode does not like having two snippets with the same identifier (will crash).
Every change in a snippet is commited and pushed independently.
Snippets are synchronized (pulled) with the remote repository is done every 10 minutes (if the option is enabled) or when the Update snippets
item was chosen in the menu.
In case of conflict during the merge, the remote repository has priority.
Probably a lot.
Backup your snippets and your git repository. Expect bugs, crashes, synchronization issues, data and hair loss.
First a quick word on the architecture:
The plugin does some swizzling with the IDECodeSnippetRepository class from IDECodeSnippetLibrary.ideplugin (/Applications/Xcode.app/Contents/PlugIns/IDECodeSnippetLibrary.ideplugin).
IDECodeSnippetRepository is modified so to make it possible to attach data stores (ACCodeSnippetDataStoreProtocol).
Here's a colourful schematic to make you even more confused:
If you want to contribute, send me a pull request.
Ideas of improvements: