Frage

I am creating a plugin for Xcode. Which would download code snippets from remote location and drop into Xcode user snippets folder. which is

~/Library/Developer/Xcode/UserData/CodeSnippets   

Every thing is working fine except that I need to restart the Xcode every time I download code snippets.I want to load newly added code snippets without restarting Xcode.

Any suggestions?

War es hilfreich?

Lösung

I recently wrote a similar plugin to synchronize snippets with a git repository. You can check the source code here: https://github.com/acoomans/ACCodeSnippetRepositoryPlugin.

Having the snippet library update when snippets change (both way) isn't trivial and required swizzling XCode' internals classes.

Xcode has a IDECodeSnippetRepository class responsible of saving snippets on disk when created or edited, and deleting them when removed.

ACCodeSnippetRepositoryPlugin has a IDECodeSnippetRepositorySwizzler class that swizzle the saveUserCodeSnippetToDisk: and removeCodeSnippet: methods with custom implementations of my own, syncing the snippet with the git repo.

enter image description here

Actually, to be really precise, my IDECodeSnippetRepositorySwizzler can have multiple code snippet data stores attached and will call the addCodeSnippet: and removeCodeSnippet: methods on each of them when the create/edit/delete events happen.

ACCodeSnippetRepositoryPlugin was intended to be able to manage multiple snippets sources (like git, gist, etc...) but I didn't finished implementing it. I giving this precision because, I don't know with what you want to synchronize your snippets, but I may make sense to add your functionality to ACCodeSnippetRepositoryPlugin.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top