LoginSignup
0
1

More than 3 years have passed since last update.

【Xcode】CounterpartSuffixesを設定してファイル移動をちょっと楽にする

Posted at

はじめに

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)(右)が開かれます。
スクリーンショット 2021-02-27 11.19.32.png

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

最後に

途中インターフェースが表示されるのが微妙ですが、慣れれば便利そうです。
プロジェクト内でアーキテクチャやファイルの命名規則が定まっていると、より効果を発揮しそうです。

関連リンク

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1