|
| 1 | +--- |
| 2 | +name: code-style |
| 3 | +description: iOS platform rules, Swift conventions, dependency injection patterns, and code quality standards for ADAMANT iOS. Use when writing or reviewing code. |
| 4 | +license: Apache-2.0 |
| 5 | +compatibility: Swift 5.9+, iOS 15.0+, UIKit, Swinject |
| 6 | +metadata: |
| 7 | + project: adamant-ios |
| 8 | + domain: code-quality |
| 9 | +--- |
| 10 | + |
| 11 | +# Code Style and Quality |
| 12 | + |
| 13 | +Code style conventions, platform rules, and quality standards for ADAMANT iOS. |
| 14 | + |
| 15 | +## iOS Platform and Swift Rules |
| 16 | + |
| 17 | +- **Target iOS 15.0+** as specified in `Podfile` and package manifests |
| 18 | +- **Use Swift 5.9+** language features as appropriate |
| 19 | +- **Follow UIKit patterns**; this is not a SwiftUI project |
| 20 | +- **Respect iOS lifecycle events** and state restoration |
| 21 | +- **Handle memory warnings and background transitions** properly |
| 22 | +- **Use `@MainActor`** or `DispatchQueue.main.async` for UI updates from background threads |
| 23 | +- **Avoid force unwrapping (`!`)** except in truly safe scenarios; prefer optional binding or guard statements |
| 24 | +- **Use Swift's type safety and value semantics** where appropriate |
| 25 | + |
| 26 | +## Dependency Injection Rules |
| 27 | + |
| 28 | +- **All services must be registered** in appropriate assembly files (`Adamant/App/DI/*`, module-specific assemblies) |
| 29 | +- **Use protocol-based abstractions** defined in `Adamant/ServiceProtocols/` |
| 30 | +- **Follow Swinject container patterns** already established in the codebase |
| 31 | +- **Prefer constructor injection** over property injection |
| 32 | +- **Use `.inObjectScope(.container)`** for singleton services |
| 33 | +- **Do not create service instances directly**; resolve them through the DI container |
| 34 | + |
| 35 | +## Code Style and Quality Rules |
| 36 | + |
| 37 | +- **Follow existing code style and patterns** in the repository |
| 38 | +- **SwiftLint is configured** but many rules are disabled (see `.swiftlint.yml`); follow the enabled rules strictly |
| 39 | +- **SwiftFormat configuration exists** (`.swiftformat`); use it for consistent formatting |
| 40 | +- **Prefer clarity over cleverness** |
| 41 | +- **Write self-documenting code**; add comments only when necessary to explain "why" not "what" |
| 42 | +- **Keep functions focused and reasonably sized** |
| 43 | +- **Avoid massive view controllers**; extract logic to services, view models, or coordinators |
| 44 | +- **Use extensions** to organize code by protocol conformance or functionality |
| 45 | +- **Follow Swift naming conventions**: clear, descriptive names without unnecessary abbreviations |
| 46 | + |
| 47 | +## Protocol and Compatibility Rules |
| 48 | + |
| 49 | +- **Keep transaction bytes, signing behavior, and verification** compatible with ADAMANT network expectations unless a coordinated protocol update is planned |
| 50 | +- **For protocol-impacting changes**, align with AIPs and update related docs/spec references |
| 51 | +- **Maintain backward compatibility** with existing user data and Core Data models |
| 52 | +- **Use Core Data migrations properly** when schema changes are required |
| 53 | +- **Test migration paths** from previous app versions |
| 54 | + |
| 55 | +## Change Discipline |
| 56 | + |
| 57 | +- **Prefer focused patches** with explicit rationale |
| 58 | +- **Preserve backward compatibility** for user data and persisted state where possible |
| 59 | +- **When touching legacy code**, improve locally without broad unrelated rewrites |
| 60 | +- **Add or update tests** near the changed behavior |
| 61 | +- **Update localization strings** when adding new user-facing text |
| 62 | +- **Update all supported languages** or mark missing translations with English fallback |
| 63 | + |
| 64 | +## UX Rules for Security-Critical Flows |
| 65 | + |
| 66 | +- **Keep onboarding fast**, but do not hide irreversible risk |
| 67 | +- **Preserve clear passphrase responsibility warnings**; never imply recoverability when none exists |
| 68 | +- **Keep transaction confirmations explicit and informative** |
| 69 | +- **Avoid introducing friction** that does not improve security or safety |
| 70 | +- **Provide clear feedback** for all user actions |
| 71 | +- **Handle loading states and network delays** with appropriate UI indicators |
| 72 | +- **Maintain accessibility support** (VoiceOver, Dynamic Type, etc.) |
| 73 | + |
| 74 | +## When to Use This Skill |
| 75 | + |
| 76 | +Activate this skill when: |
| 77 | + |
| 78 | +- Writing new code |
| 79 | +- Reviewing code for style compliance |
| 80 | +- Refactoring existing code |
| 81 | +- Setting up DI registrations |
| 82 | +- Working with Core Data models |
| 83 | +- Making UI changes |
| 84 | + |
| 85 | +## See Also |
| 86 | + |
| 87 | +- [Swift Rules](references/SWIFT-RULES.md) for detailed Swift conventions |
| 88 | +- [DI Patterns](references/DI-PATTERNS.md) for dependency injection examples |
0 commit comments