| name | ha-ios-code-style |
|---|---|
| description | Swift code style, linting, logging, assets, and idioms for Home Assistant iOS. Use when writing or formatting Swift, running SwiftFormat/SwiftLint, referencing SF Symbols or Material Design icons, logging, or using the with() helper. |
# Check for lint issues (does not modify files)
bundle exec fastlane lint
# Auto-fix lint issues (run before committing!)
bundle exec fastlane autocorrectAlways run bundle exec fastlane autocorrect after making changes and before committing.
| Tool | Config File | Purpose |
|---|---|---|
| SwiftFormat | .swiftformat |
Code formatting (120 char max, before-first wrapping) |
| SwiftLint | .swiftlint.yml |
Code quality rules |
| Rubocop | .rubocop.yml |
Ruby/Fastlane code |
| YamlLint | .yamllint.yml |
YAML files |
- Max line width: 120 characters
- Wrap arguments/parameters/collections:
before-first selfkeyword: only in initializers (--self init-only)- Guard else: same line
- Headers: stripped (no file header comments)
- No
force_castorforce_try - Keep cyclomatic complexity low
- No assigning to
Current.*outside tests - Use
SFSafeSymbolsfor SF Symbol references:
// ❌ Wrong
Image(systemName: "house")
// ✅ Correct
Image(systemSymbol: .house)Use Current.Log (XCGLogger) — never print or NSLog:
Current.Log.info("Connected to \(server.info.name)")
Current.Log.error("Failed: \(error.localizedDescription)")
Current.Log.verbose("Debug detail")with(_:update:) in Sources/Shared/Common/With.swift is used for fluent inline initialization:
public lazy var webhooks = with(WebhookManager()) {
$0.register(responseHandler: ..., for: .updateSensors)
}- SF Symbols via
SFSafeSymbolslibrary (Image(systemSymbol: .house)), never the string-based API - HA domain/entity icons via the
MaterialDesignIconsenum (auto-generated from JSON); names carry anIconsuffix (e.g..lightbulbIcon), andDomain.icon(deviceClass:state:)provides domain-appropriate icons - Asset catalogs in
Sources/Shared/Assets/SharedAssets.xcassets