Download - About Swift-Clean
![Page 1: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/1.jpg)
![Page 2: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/2.jpg)
Swift-Clean
![Page 3: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/3.jpg)
http://swiftcleanapp.com/
Swift-Clean
![Page 4: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/4.jpg)
Swift-Cleanとは?
• Swiftのコードフォーマッター
• フォーマットルールを設定することができる
• フォーマットはビルド時に適用される
![Page 5: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/5.jpg)
有料です
Free Trialあり
![Page 6: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/6.jpg)
きっかけ
• 最近、Swiftのソースレビューをしている • Swiftのフォーマットのレビューの方針がない
• 個人的にはどこにスペースを入れるとか、どこで改行するとか割とどうでも良い
• でも、やっぱり統一されていた方が気持ち良い
![Page 7: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/7.jpg)
Swift-Cleanの良いところ
• アンケートに答えていくとSwiftStyleSettings.plistが生成される
• これをもとにSwift-Clean.appが警告を出してくれたりする
![Page 8: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/8.jpg)
あなたのフォーマットルールは?
![Page 9: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/9.jpg)
yidev-swiftフォーマットを作ろう
![Page 10: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/10.jpg)
1/39 (AutoFix)
クラス宣言などの : の前後のスペーシング
What should the spacing around the colon look like in a class declaration?
![Page 11: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/11.jpg)
2/39 (AutoFix)
メソッドのreturn オペレータのスペーシングは
What should the spacing around the return operator look like in a method signature?
![Page 12: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/12.jpg)
3/39
クラス宣言の { を始める位置は?
Where should the open curly brace be in relation to a class declaration?
![Page 13: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/13.jpg)
4/39
メソッド宣言の { を始める位置は?
Where should the open curly brace be in relation to a method declaration?
![Page 14: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/14.jpg)
5/39 (AutoFix)
メソッドの ( はスペースを空けるべきか?
Should there be a space before the opening parentheses in a method signature?
![Page 15: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/15.jpg)
6/39 (AutoFix)
オペレータ宣言の ( の前にはスペースを入れるべきか?
Should there be a space before the opening parentheses in a operator function signature?
![Page 16: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/16.jpg)
7/39 (AutoFix)
メソッド呼び出しの ( の前にはスペースを入れるべきか?
Should there be a space before the opening parentheses in a method call?
![Page 17: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/17.jpg)
8/39 (AutoFix)
メソッドの引数の : の周りにはスペースをどう入れるか?
What should the spacing around the colon look like in a method signature?
![Page 18: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/18.jpg)
9/39 (AutoFix)
変数宣言の : の周りにはスペースをどう入れるか?
What should the spacing around the colon look like in a variable declaration?
![Page 19: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/19.jpg)
10/39
for文の { はどこに置くべきか?
Where should the open curly brace be in relation to a loop declaration?
![Page 20: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/20.jpg)
11/39
if文の { はどこに置くべきか?
Where should the open curly brace be in relation to an if-statement declaration?
![Page 21: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/21.jpg)
12/39
switch文の { はどこに置くべきか?
Where should the open curly brace be in relation to a switch statement declaration?
![Page 22: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/22.jpg)
13/39
return文の上に空の行を入れるべきか?
Should there be an empty line above return statements?
![Page 23: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/23.jpg)
14/39 (AutoFix)
四則演算の周りにスペースを入れるべきか?
What should the spacing around math operators look like?
![Page 24: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/24.jpg)
15/39 (AutoFix)
{ の前にはスペースを入れるべきか?
Should there be a space before opening braces?
![Page 25: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/25.jpg)
16/39 (AutoFix)
, のあとにスペースを入れるべきか?
Should there be a space after commas?
![Page 26: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/26.jpg)
17/39
メソッド間にどれくらい空行を入れるべきか?
How many empty lines should there be between (main, non-nested) method bodies?
![Page 27: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/27.jpg)
18/39 (AutoFix)
メソッドのジェネリクス宣言の周りにスペースを入れるか?
What should the spacing around generic declarations look like in a method signature?
![Page 28: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/28.jpg)
19/39 (AutoFix)
カスタムプロパティのセッターの ( の前にスペースを入れるか?Should there be a space before the opening parentheses of a custom property setter?
![Page 29: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/29.jpg)
20/39 (AutoFix)
型指定の前にスペースを入れるか?
Should there be a space before the type specifier?
![Page 30: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/30.jpg)
21/39 (AutoFix)
論理演算子の周りのスペースはどうする?
What should the spacing around logical operators look like?
![Page 31: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/31.jpg)
22/39 (AutoFix)
代入時のスペースはどうする?
What should the spacing around the assignment operator look like?
![Page 32: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/32.jpg)
23/39
// MARK: コメントの上には空行をどれくらい入れるべきか?
How many empty lines should there be above a // MARK: declaration?
![Page 33: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/33.jpg)
24/39
// MARK: コメントの下には空行をどれくらい入れるべきか?
How many empty lines should there be below a // MARK: declaration?
![Page 34: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/34.jpg)
25/39
モジュールインポートの最後の行の下にどれくらい空行を入れるか?How many empty lines should there be below the last module import?
![Page 35: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/35.jpg)
26/39
モジュールインポートの最初の行の上にどれくらい空行を入れるか?How many empty lines should there be above the first module import?
![Page 36: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/36.jpg)
27/39 (AutoFix)
Dictionaryの : の周りにどうやってスペースを入れるか?
What should the spacing around the colon look like in a dictionary?
![Page 37: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/37.jpg)
28/39 (AutoFix)
メソッド呼び出しの際の : の周りはどうスペーシングするか?
What should the spacing around the colon look like in a function call?
![Page 38: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/38.jpg)
29/39
Swiftファイルの最後の行にはどれくらい空行を入れるべきか
How many empty lines should there be at the end of every Swift file?
![Page 39: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/39.jpg)
30/39
クラス名は1文字目を大文字にすべきか?
Should class names be capitalized?
![Page 40: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/40.jpg)
31/39
メソッド名は1文字目を大文字にすべきか?
Should function names be capitalized?
![Page 41: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/41.jpg)
32/39
変数名は1文字目を大文字にすべきか?
Should variable names be capitalized?
![Page 42: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/42.jpg)
33/39
enum名は1文字目を大文字にすべきか?
Should enum names be capitalized?
![Page 43: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/43.jpg)
34/39
struct名は1文字目を大文字にすべきか?
Should struct names be capitalized?
![Page 44: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/44.jpg)
35/39
typealias時の名前は1文字目を大文字にすべきか?
Should typealias names be capitalized?
![Page 45: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/45.jpg)
36/39
定数名は1文字目を大文字にすべきか?
Should static variable names be capitalized?
![Page 46: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/46.jpg)
37/39
struct宣言時の { はどうすべきか?
Where should the open curly brace be in relation to a struct declaration?
![Page 47: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/47.jpg)
38/39
enum宣言時の { はどうすべきか?
Where should the open curly brace be in relation to an enum declaration?
![Page 48: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/48.jpg)
39/39
コーディングルール違反時はビルドエラーにするか?ワーニングにするか?Do you want Swift-Clean to show code violations as build errors or warnings in Xcode?
![Page 49: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/49.jpg)
設定方法
![Page 50: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/50.jpg)
設定方法
Swift-Cleanアプリを立ち上げる
![Page 51: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/51.jpg)
設定方法
Customでさっきのアンケート画面に
![Page 52: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/52.jpg)
設定方法
StackoverflowアカウントSign-inしたユーザーのアンケート結果
![Page 53: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/53.jpg)
設定方法
アンケートに回答したすべてのユーザーの平均
![Page 54: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/54.jpg)
設定方法
除外ファイルなどの設定
![Page 55: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/55.jpg)
設定方法
プロジェクトファイルを追加
![Page 56: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/56.jpg)
設定方法
AutoFixでさきほどのアンケートでAutoFixと記載されていた項目を自動で修正してくれる
![Page 57: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/57.jpg)
設定方法
Install Run Scriptをクリック
![Page 58: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/58.jpg)
設定方法
Build PhasesにSwift-Clean Run Scriptが追加される不要だったら削除すればOK
![Page 59: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/59.jpg)
設定方法
• 先ほど生成したSwiftStyleSettings.plistを.xcodeprojと同じ階層に保存して、あとはBuildすればOK
![Page 60: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/60.jpg)
こんな感じ
• モジュールインポートの最後の行の下は空行1つにしましょう
• メソッド名はキャメルケースにしましょう などなど
![Page 61: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/61.jpg)
注意
![Page 62: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/62.jpg)
ビルドするごとに…
Free Trial版だとビルドするごとに出てくる
![Page 63: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/63.jpg)
うざかったら
Build PhasesにSwift-Clean Run Scriptが追加される不要だったら削除すればOK
![Page 64: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/64.jpg)
コードフォーマットとか好みでしかないし、どうでもいい、でも整ってる方が気持ち良い
→ チーム開発時はツールで自動化したい
→ Swift-Cleanは一つの手段
まとめ
![Page 65: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/65.jpg)
• アンケート形式で答えられるので、チーム開発で多数決とって決めたい場合にちょうど良いかも
• 150ドルのSingle Site Licenseが用意されている
まとめ
![Page 66: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/66.jpg)
• 第21回 yidevで作成したSwiftStyleSettings.plistはhttps://github.com/mnat44/yidev-21-swift-style-settings-for-swift-clean にアップロードしています
補足
![Page 67: About Swift-Clean](https://reader034.vdocuments.mx/reader034/viewer/2022051318/587a26841a28abbd388b5201/html5/thumbnails/67.jpg)
おわり