By default, Xcode supports only Apple MVC templates.
This leads to terrible inconsistency in app layers when you use different architecture.
Also, a lot of boilerplate code must be deleted, some must be added.
Because of that, I decided to create MVVM friendly templates.
The MVVM style is heavily inspired by Kickstarter's iOS App.
That means, all View Models are composed from inputs
and outputs
and implements Type
protocol. All Controllers created with MVVM template requires ViewModel class.
All templates are separated in to sections with MARK: -
comments.
This creates fine document outline when you press ctrl ^ + 6.
Currently, this repository contains templates for:
Templates are located in user's Library folder where Xcode keeps custom configuration. To install templates, just copy them to correct location. However, better way to stay up-to date with latest repo version is to create symbolic link for whole templates folder.
First of all, clone this repository:
$ git clone https://github.com/josefdolezal/xcode-goodies
Once the repository is clonned, create the symbolic link:
$ TEMPLATES_GROUP="<My templates>"
$ cd xcode-goodies # Switch to the repository
$ ln -s "$PWD" ~/Library/Developer/Xcode/Templates/"$TEMPLATES_GROUP"
Be sure you replaced <My templates>
placeholder with group name you want to see in Xcode.
If everything went right, you should see new section at the bottom of the list when you press cmd β + n.
Similary as templates, Xcode supports custom code snippets.
A lot of standard snippets are included in base Xcode installation, however it's not enough!
Do you remember this few lines of code you have to write whenever you want to disable Swiftlint here and then enable it somewhere else again?
Does it take you at least second try to write correct syntax of Localizable.strings
?
Oh, and did I mention the Realm API which is not suggested by Xcode because it's implemented with static methods?
Custom snippets are here for rescue!
See the list below and choose your favorite.
The installation is alson done with symlinks, but snippets does not support subfolders. Snippets must be linked separately:
$ cd xcode-goodies/snippets # Switch to the repository
$ ln -s "$PWD"/*.codesnippet ~/Library/Developer/Xcode/UserData/CodeSnippet
Note that if you have your own snippets already, there may be some name conflicts during installation. In that case, rename the conflicted files (your or these in repository) and run the installation script again.
To see the effect, restart the Xcode.
Effect | Shortcut |
---|---|
Switch build scheme | ctrl ^ + cmd β + [ or ctrl ^ + cmd β + ] |
Switch product destination (simulator) | ctrl ^ + alt β + cmd β + [ or ctrl ^ + alt β + cmd β + ] |
Effect | Shortcut |
---|---|
Move focus to different editor | cmd β + j |
Open assistant editor * | cmd β + alt β + enter β© |
Close assistant editor | cmd β + enter β© |
Switch tab | cmd β + shift β¬ + [ or cmd β + shift β¬ + ] |
Open new tab | cmd β + t |
* Don't forget to check Use Focused Editor in Xcode Navigation preferences, or each new file will be opened in the standard editor every time.
Effect | Shortcut |
---|---|
Open quickly | cmd β + shift β¬ + o |
Show completions | ctrl ^ + space or esc* |
Re-indent selection | ctrl ^ + i |
* Must be turned on explicitly in Text Editing under Code completions options.
Effect | Shortcut |
---|---|
Move to the beginning of the line | cmd β + β |
Move to the end of the line | cmd β + β‘ |
Move to the beginning of the word | alt β + β |
Move to the end of the word | alt β + β‘ |
File outline | ctrl ^ + 6 |
Line navigation may be also combined with backspace β¬ to achieve ultimate deletion combos.
Effect | Shortcut |
---|---|
Build target | cmd β + b |
Run product | cmd β + r |
Run all tests | cmd β + r |
Run current test | cmd β + ctrl ^ + alt β + u |
Clean project | cmd β + shift β¬ + k |
Clean build folder | cmd β + alt β + shift β¬ + k |
Effect | Shortcut |
---|---|
Toggle console | cmd β + shift β¬ + y |
Toggle navigator | cmd β + 0 |
Toggle utilities | cmd β + alt β + 0 |