Rulepython
Swift Rule
Swift Rules
Version: Swift 6 / 6.2
Tooling
- Build: Swift Package Manager or Xcode
- Testing: XCTest with coverage >= 85%
- Linting: SwiftLint
Best Practices (2026)
- Use "Approachable Concurrency" philosophy (Swift 6.2)
- Use
@MainActorfor UI code - guarantees main thread execution - Use
.task {}modifier - auto-cancels when view disappears - Use actors for mutable state isolation
- Mark types as
Sendablefor cross-concurrency-domain safety
Swift 6.2 Concurrency
// Default MainActor isolation for modules
// Enable: -default-isolation MainActor
// Explicit concurrent execution
@concurrent
func processData() async -> Data {
// Runs in parallel, not on MainActor
}
// Nonisolated async inheritance
// Inherits caller's actor instead of own isolation
nonisolated func helper() async {
// Inherits isolation from caller
}
SwiftUI Patterns
@Statefor local state@Bindingfor parent-child communication@Observable(macro) for external state (iOS 17+)- Use
NavigationStackwith.navigationDestinationfor type-safe navigation
Progressive Disclosure
Swift 6.2 principle: Only learn concurrency concepts as you need them:
- Sequential code first
- Add async/await for suspending APIs
- Add actors/Sendable only when introducing parallelism
MoAI Integration
- Use Skill("moai-lang-swift") for detailed patterns
- Follow TRUST 5 quality gates