Instruction file imported from rpgraffi/convert-compress (
.cursor/rules/swift.mdc). Copyright stays with the author.
Swift 6.2 / macOS 14.6+
Information
- bundle identifier: raffistudio.image-tools
Architecture & State
- Prefer
structoverclassfor data models (value semantics prevent shared mutable state) - Design stateless, pure functions where possible
- Use
@State,@Observable,@Bindingappropriately; keep state minimal and localized - Pass dependencies explicitly; avoid singletons except for true app-wide services
- Model state transitions with enums (associated values for data)
Code Quality
- Single Responsibility: each type/function does one thing well
- Small, focused functions (< 20 lines ideal)
- Immutable by default: use
letovervar - Safe optional handling: use
if let,guard let, or nil coalescing—never force unwrap in production code - Leverage Swift's type system: use enums, protocols, and generics for compile-time safety
- Explicit > Implicit
SwiftUI Patterns
- Extract reusable components into separate views
- Keep view bodies readable: extract complex logic to computed properties or ViewModels
- Use
@ViewBuilderfor conditional/compositional layouts - Prefer declarative over imperative patterns
General
- Follow Swift API Design Guidelines for naming
- Don't overengineer; prefer simplicity
- Research current APIs and patterns when uncertain
Folders
- Use
convert-compress/Core/Modelsfor value-type domain models - Use
convert-compress/Core/Constantsfor constants (includingStorageKeys) - Use
convert-compress/Core/Loggingfor theAppLoggernamespace - See
conventions.mdcfor the complete project layout and naming rules