Skip to content

barbaramartina/swift-code-snippets

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

swift-code-snippets

Sharing my code snippets for XCode and Swift.

I've prefixed all my snippets with bmr- so can be easily found using autocomplete.

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.

Install

To install these snippets you could:

  1. 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).
  2. You can install the xcodesnippet gem.

Installing using 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

Create

To create your own snippets select your code, drag&drop to the Snippets Library, at the bottom of the Utility Panel (at the right).

Share

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.

Simple 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

Sharing with Alcatraz

Only older XCode versions You could also share, from XCode, using some Alcatraz plugin like XCSnippetr, or adapting SwiftCodeSnippets to use your own repository.

Sharing in this repo

If you want to share your snippets in this repo you have to do the following:

  1. Fork the repo.
  2. Open the app under exporter/ in XCode and run the app in your mac.
  3. A panel will open, choose the snippets main directory.

  1. Another panel will open inmediately, choose the output directory.

5. Go to your output directory and you will find the exported files there.
  1. Add your snippets and make a PR.

Other repos with snippets

Checkout also these repos for more snippets:

  1. burczyc
  2. Mattt.
    This last one still does not have any snippet for Swift and can not be forked yet, but I'm sure cool reusable snippets will appear soon there.

About

Sharing my code snippets for Swift 3

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages