はじめに
Xcodeでは、ファイルにCounterpart(=対の片方)という概念があります。
デフォルトでは、実装ファイルとヘッダファイルがこの関係にあたります。
Jump to Counterpart
Counterpartへのジャンプは、以下のいずれかで可能です。
- Navigate > Jump to Next/Previous Counterpart
-
Ctrl + Command + ↑ or Ctrl + Command + ↑
- 現在のエディタ上で移動
-
Ctrl + Option + Command + ↑ or Ctrl + Option + Command + ↑
- 隣のエディタ上で移動
ViewStream.swift
(左)を開いた状態で Ctrl + Option + Command + ↑ を押すと、隣のエディタでViewStream.swift(Interface)
(右)が開かれます。
Counterpartの設定
Counterpartはdefaults
コマンドによって、カスタマイズすることが出来ます。
$ defaults write com.apple.dt.Xcode IDEAdditionalCounterpartSuffixes -array-add "ViewController" "ViewStream" "ViewDataSource"
$ defaults read com.apple.dt.Xcode IDEAdditionalCounterpartSuffixes
(
ViewController,
ViewStream,
ViewDataSource
)
(設定を反映させるためには、Xcodeを再起動が必要です。)
この状態で Ctrl + Command + ↓
を繰り返した場合、ファイル遷移は以下のようになります。
ViewController
↓
ViewStream(Interface)
↓
ViewStream
↓
ViewDataSource(Interface)
↓
ViewDataSource
↓
ViewController(Interface)
↓
ViewController // 1周
↓
...
リセット
$ defaults delete com.apple.dt.Xcode IDEAdditionalCounterpartSuffixes
最後に
途中インターフェースが表示されるのが微妙ですが、慣れれば便利そうです。
プロジェクト内でアーキテクチャやファイルの命名規則が定まっていると、より効果を発揮しそうです。