A useful suggestion explains the reasoning.
Enable JavaScript to explore numbered annotations. The rule examples below remain readable without it.
Less time debating style. More time building something great. Bring clear, configurable conventions to your Swift projects.
Three real-world scenarios. Seven annotated findings. Follow each suggestion from the exact code location to a considered revision.
if messages.count == 0 { }
// Suggestion: messages.isEmptyEnable JavaScript to explore numbered annotations. The rule examples below remain readable without it.
Interactive teaching examples, not live analysis. Suggested revisions may change error handling; review them against your application requirements.
Explore a convention, understand the feedback, and see a better approach.
Prefer isEmpty when checking a collection for emptiness.
if items.count == 0 { }if items.isEmpty { }Prefer isEmpty.
Opt-in rule: enable empty_count.
Read the official rule ↗Focus on valid, compilable Swift code.
Run swiftlint lint locally for actionable feedback.
Add checks to your Xcode or Swift Package build.
Commit your configuration so the team shares conventions.
Start with a small, deliberate configuration. Expand it as your team gets comfortable.
opt_in_rules: - empty_count excluded: - Pods force_cast: warning
Install on macOS with Homebrew.
brew install swiftlint swiftlint lintOfficial guide ↗
Choose a few rules your team can explain. For new projects, agree on the initial configuration before the first large feature lands.
opt_in_rules: - empty_count - empty_string - explicit_init excluded: - Pods
These are the opt-in rules used in our examples. Commit the configuration alongside your source.
Check the project, apply supported corrections, then inspect the diff. Keep behavior-changing edits small enough to review carefully.
swiftlint lint swiftlint --fix git diff
For a mature codebase, introduce conventions in stages. Review exclusions and the official baseline workflow rather than mixing a repository-wide cleanup with feature work.
No. Only supported corrections can be applied automatically. Review changes and use human judgment for semantic changes.
Yes. Start with a focused rule set and exclusions. Explore the official baseline feature to manage existing violations.
Review the rule directory, distinguish default and opt-in rules, and agree on conventions with your team.
Run locally for fast feedback, then integrate with build tooling. SwiftLint expects valid, compilable Swift source.