Skip to content

Latest commit

 

History

History
76 lines (45 loc) · 3.68 KB

DOCS.md

File metadata and controls

76 lines (45 loc) · 3.68 KB

👨‍🏫 Docs

X-SwiftFormat is a Xcode Plugin built on top of two cool frameworks:

  1. Formatting technology for Swift source code - https://github.com/apple/swift-format
  2. SwiftPM package for SwiftSyntax library - https://github.com/apple/swift-syntax

⚠️ Please make sure your setup is complete (see how here)

1) Open Swift file with Xcode

1-light 1-dark

2) Once you are editing a Swift file in Xcode, you can format this file using the X-SwiftFormat Extension. Just go to EditorX-SwiftFormatFormat Swift Code. Done, code is formatted with default settings.

2-light 2-dark

3) You can open X-SwiftFormat app to change some settings. Read more here

3-light 3-dark

4) I will just change two options here, Line Length = 120 and use Tabs = 1 . We have more options to change.

4-light 4-dark

5) Formatting the code again will use my custom settings, i.e will use tabs and 120 is the maximum allowed length of a line, in characters.

5-light 5-dark

6) Another cool feature is the ability to suppress formatting within a section of source code. Read more here

  1. // swift-format-ignore
  2. // swift-format-ignore: OrderedImports
  3. // swift-format-ignore: DoNotUseSemicolons

Using those rules, imports will not be sorted, the block [17-23] will not be formatted and we can use semicolons on the block [26-30] .

6-light 6-dark

7) X-SwiftFormat app also allows setting rules to suppress formatting. Ordered Imports is now disabled.

7-light 7-dark

8) This means even with no comments, imports will not be sorted.

8-light 8-dark

9) After version 1.1, its possible to have multiple environments, this will help if you work with multiple porjects and multiple configurations. Press the (+) and add the name you want.

9-light 9-dark

10) You can switch between configuration using the dropdown.

10-light 10-dark


I'm Rui Aureliano, iOS and macOS Engineer at Olá Brothers. We make Sip 🤓

Linkedin | Twitter | Github | Stackoverflow