---
description: Swift/iOS code style and naming conventions
globs: "**/*.swift"
---

## Swift Code Style Rules

### Naming

- Types: UpperCamelCase (`FlightSearchViewModel`)
- Functions/Properties: lowerCamelCase (`fetchFlightData()`)
- Constants: lowerCamelCase (`let maxRetryCount = 3`)
- Protocols: adjective or noun (`Configurable`, `DataSource`)
- Boolean: prefix with is/has/should (`isLoading`, `hasData`)

### Structure

- MARK comments to organize: `// MARK: - Properties`, `// MARK: - Lifecycle`
- Extension per protocol conformance
- Max function length: ~40 lines  -  split if longer
- Max file length: ~400 lines  -  split into extensions

### Patterns

- Guard early, return early  -  avoid deep nesting
- Use `[weak self]` in escaping closures, then `guard let self` inside
- Prefer `let` over `var`
- Prefer value types (struct/enum) over reference types (class) when possible
- Use `Result` type or async/await for error handling, not optional returns

### Don'ts

- No force unwraps (`!`) except IBOutlets
- No force casts (`as!`)  -  use `as?` with guard
- No implicitly unwrapped optionals except IBOutlets and test setup
- No magic numbers  -  use named constants
- No `print()`  -  use `os_log` or `Logger`
