My collection of useful Xcode code snippets! It has been a great time-saver for me so I decided to share it with everyone :)
- Go to your Xcode user's code snippets directory. Create one if it doesn't exist.
open ~/Library/Developer/Xcode/UserData/CodeSnippets
- In that folder, you can either:
- run
git init
, thengit pull https://github.com/hlung/Xcode-Snippets
to that folder (recommended, easy update), OR... - download ZIP of this repo, extract
.codesnippet
files to that folder
- run
- Restart Xcode.
- Enjoy!
Note: Each code snippet has a unique IDECodeSnippetIdentifier
key, which Xcode generates when I created each snippet. There's a small chance that they will collide with your existing snippets. Fingers crossed.
In Xcode, open a workspace and toggle the right sidebar to be visible. On the bottom, there is a panel with four icons in the header. Click on the { }
icon to open the Code Snippets Library.
Highlight your code block and drag it to the Code Snippet panel. Make sure to match the suggested platform, language, and completion scope.