When working within a team, it is generally a good practice to follow a common coding convention and style guide. SwiftLint is a nice tool in this regard. It's really easy to get started with adding SwiftLint to an existing project. Install the library using brew.
brew install swiftlint
Add the following script in the run phase under Xcode Build Phases section
if which swiftlint >/dev/null; then
swiftlint
else
echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi
This will enable the default SwiftLint configuration to be used to lint the code base. We can have custom rules defined under .swiftlint.yml
file placed inside the project root. A sample config file is given below.
excluded:
- Carthage
- Pods
- SwiftLint/Common/3rdPartyLib
disabled_rules:
- trailing_whitespace
- identifier_name
- type_body_length
- large_tuple
opt_in_rules:
- unneeded_parentheses_in_closure_argument
force_cast: warning
line_length:
warning: 160
file_length:
warning: 1000
function_body_length:
warning: 100
error: 200
allowed_symbols: "_"
reporter: "xcode"
I did a bug fix and raised a pull request which got merged in release v0.32.0!