macOS, iOS

Swift format 프로젝트에 적용하기

SweetDev 2019. 12. 19. 14:32

# swift 스타일 맞추기

## google swift 문서 참조하기
https://google.github.io/swift/ 
이 문서에 있는 것을 표준으로 사용한다

## SwiftFormat extension 사용하기

https://github.com/nicklockwood/SwiftFormat

1. 프로젝트를 클론받는다 ( Download ZIP ) 
2. 폴더 안에서 EditorExtension > SwiftFormat for Xcode.app을 응용 프로그램 폴더로 옮긴다
3. 시스템 환경설정 > 확장 프로그램 > 모두 에서 SwiftFormat for Xcode를 체크해준다. 
4. SwiftFormat 응용프로그램을 열어서, Infer Options Automatically를 체크 해제하고, indent > Indent를 4에서 2로 바꿔준다. 
5. Xcode와 컴퓨터를 재부팅한다.
6. Xcode에서 Editor > SwiftFormat 탭에서 포매팅 할 수 있어진다.

Format Selected Source : 드래그한 영역만 reformat
Format Entire File : 현재 작업중인 파일 전체 reformat


## Xcode 키 바인딩 추가해주기
1. Xcode > Preference (command , )에서 Key Bindings 탭을 선택한다
2. format entire file을 control + option + command + i로 해준다.