Sharing my code snippets for XCode and Swift.
I've prefixed all my snippets with bmr- so can be easily found using autocomplete.
I've also included in this repo snippets I found useful from data structures and algorithms available in the Swift Algorithm Club.
These snippets are named with Swift Algorithms Club at the beginning.
To install these snippets you could:
- Copy&Paste the code (under the content section of the YAML .swift files) and create the snippet yourself again by hand, completing the rest of the properties (such as giving a title, a summary, a shortcut and so on).
- You can install the xcodesnippet gem.
To use the gem you must execute this command (you must have ruby gems already installed in your system):
$ gem install xcodesnippet
After that, download the snippets in this repo or in any other repo which also offers YAML format (check any of the snippets here as an eample of the format structure).
Go to the command line and execute:
$ xcodesnippet install path/to/snippet-file.swift
To create your own snippets select your code, drag&drop to the Snippets Library, at the bottom of the Utility Panel (at the right).
You do not necessarily need to use this repo nor share your snippets here, there are different ways to share them, even not using the YAML format I'm using here.
You can find your local snippets going to:
~/Library/Developer/Xcode/UserData/CodeSnippets
And you have different options for sharing.
Under the directory above, you'll find files with the extension .codesnippet.
Just send these files to somebody else, who copy them inside his own /CodeSnippets
directory.
And that's all.
Only be careful not to repeat the same identifier for the snippets.
The ID can be seen going to
~/Library/Developer/Xcode/UserData/CodeSnippets
Only older XCode versions
You could also share, from XCode, using some Alcatraz plugin like XCSnippetr, or adapting SwiftCodeSnippets to use your own repository.
If you want to share your snippets in this repo you have to do the following:
- Fork the repo.
- Open the app under
exporter/
in XCode and run the app in your mac. - A panel will open, choose the snippets main directory.
- Another panel will open inmediately, choose the output directory.
- Add your snippets and make a PR.
Checkout also these repos for more snippets: