Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Add support for a better Xcode's Jump to Next Counterpart in Swift

If you work on a Swift project that follows the Model-View-ViewModel (MVVM) architecture or similar, you may want to jump to counterpart in Xcode from your view to your model, and then to your view model. (ie. by using Ctrl+Cmd+Up and Ctrl+Cmd+Down).

You can do this in recent versions of Xcode by setting a configuration default.

From a terminal, just type this command and press Enter:

defaults write IDEAdditionalCounterpartSuffixes -array-add "ViewModel" "View"

Restart Xcode and navigate to one of your Swift model files. You’ll see counterparts more tailored to your project architecture now:

Ctrl+Cmd+Up and Ctrl+Cmd+Down will cycle those files and their interfaces generated by SourceKit.

If you want to revert the change, simply run this in a terminal and restart Xcode:

defaults delete IDEAdditionalCounterpartSuffixes

This configuration used to work for the Objective-C family of languages, but recent versions of Xcode seem to have added support for Swift too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment