LoginSignup
4
3

More than 5 years have passed since last update.

【Xcode】 Clang-formatを自動化

Posted at

相変わらずのメモ書きです

clang-formatをbrew経由でインストール

ターミナルにて次のコマンドを入力

brew tap tcr/tcr
brew install clang-format

Xcodeにて

[Edit Schema]を開く

スクリーンショット 2017-04-22 19.02.37.png

[Run]の中の[Pre Actions]を選択

スクリーンショット 2017-04-22 19.03.25.png

自動フォーマットする対象を選ぶ

スクリーンショット 2017-04-22 19.04.13.png

スクリプトを設定する

以下のコマンドを入力する
find ${SRCROOT} -name *.[h,m] | xargs clang-format -i -style=Google
スクリーンショット 2017-04-22 19.04.37.png

あとはBuildするだけ!

※ 何もフォーマットをかけていないプロジェクトならば、ほぼ全体が変更されるのでバージョン管理しているならば別ブランチなどをきって行いましょう。

終わりに

今回設定したのは
「.hファイルと.mファイルをGoogleのフォーマットルールに沿った整形にする」といったものです。
カスタムは可能なので色々自分や現場にあったものにしておくといいでしょう。

4
3
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
4
3