AgentSkillsCN

podimo-code-practices

遵循 Podimo iOS 编码规范与最佳实践。适用于新功能的实现、代码编写,或同事代码/PR 的审查。无论是“实现功能”、“添加功能”、“创建”、“构建”、“代码审查”、“PR 审查”、“代码审查”、“检查这段代码”,还是任何 Swift/iOS 开发任务,皆可适用。

SKILL.md
--- frontmatter
name: podimo-code-practices
description: Podimo iOS coding standards and best practices. Use when implementing new features, writing code, or reviewing colleague's code/PRs. Applies to "implement feature", "add feature", "create", "build", "code review", "review PR", "review code", "check this code", or any Swift/iOS development task.

Podimo iOS Code Practices

Comprehensive coding standards for implementing features and reviewing code at Podimo.


Mode Detection

Determine the mode based on user request:

Implementation Mode

Triggers: "implement", "add feature", "create", "build", "write code", or any feature development request.

Workflow:

  1. Apply all practices below while writing code
  2. Use reusable components from PodimoUI/PodimoBrandbook
  3. Follow architecture patterns (Navigator, Services, ViewModels)
  4. Add localization keys to Localizable.strings
  5. Create unit tests alongside implementation

Review Mode

Triggers: "review", "code review", "check code", "PR review", git diff, or colleague's code.

Workflow:

  1. Read specified files or run git diff for changed files
  2. Analyze code against all practices below
  3. Verify localization keys exist in Podimo/Resources/Localizations/en.lproj/Localizable.strings
  4. Check for reusable components in PodimoCore/Sources/PodimoUI/ and PodimoCore/Sources/PodimoBrandbook/
  5. Verify unit tests exist in PodimoTests/
  6. Generate review report (see Output Format below)

Coding Practices

1. Architecture

PracticeSeverity
Use constructor injection via initWarning
Avoid @Injected, @LazyInjected property wrappersWarning
Use Navigator pattern for screen transitionsWarning
Prefer composition over inheritanceWarning
Feature modules in Features/ directory (flat structure)Suggestion
Services/Navigators registered as Factory properties in ContainerWarning
Avoid .shared singleton unless shared state is neededWarning

2. Data Layer

PracticeSeverity
Apollo queries/mutations must live in RepositoriesWarning
Services use Repositories, not NetworkService directlyWarning
ViewModels use Services, not Repositories directlyWarning

3. Events/Analytics

PracticeSeverity
Extract events to dedicated EventsService classesWarning
VMs/Services use feature EventsService, not raw EventsProtocolWarning

4. Responsibilities

PracticeSeverity
View logic in ViewModels, not ViewControllersWarning
Navigation logic in NavigatorsWarning
Events/tracking in EventsServicesWarning
DataSource as separate class (not VC extension)Warning

5. Naming Conventions

PracticeSeverityExample
No kConstantName prefixWarningkSomeInt -> someInt
Boolish names for booleansWarningaddHeader -> shouldAddHeader, formatIPad -> isIPadFormatted
Action names for methodsSuggestionfetchEpisodes(), updateState()
Avoid Swift type shadowingWarningclass TextView -> class BaseTextView

6. Protocol Rules

PracticeSeverity
Services/Repos/Managers/EventsServices: require // sourcery: AutoMockable protocolWarning
VCs/VMs/DataSources: avoid protocols (flag if present)Warning

Protocol naming (when needed):

  • Service -> Serving (e.g., AudioRecommendationServing)
  • Repository -> Storing (e.g., ShowPageStoring)
  • Manager -> Managing
  • DataSource -> DataSourcing

7. Class Structure

PracticeSeverity
Avoid Input/Output ViewModel patternWarning
@MainActor on ViewModelsWarning
@MainActor on ViewsWarning

8. SwiftUI Views

PracticeSeverity
No logic or state in views - keep dumbWarning
No @State for business logic (only UI state like animations)Warning
Use @StateObject / @ObservedObject for ViewModelWarning

9. SwiftUI ViewModels

PracticeSeverity
Must be ObservableObjectWarning
Minimize @Published propertiesWarning
Derive state from existing published properties when possibleWarning
Cache computed results to avoid rerendersWarning
No expensive work in init()Warning
No side effects in init() (Task, subscriptions, etc.)Warning

10. Encapsulation

PracticeSeverity
Avoid exposing mutable propertiesWarning
Use private(set) if external read neededWarning

11. Design System

PracticeSeverity
Use PodimoFonts - no hardcoded fontsWarning
Use PodimoColors - no hardcoded colorsWarning
Use UIConstants.paddingX - no hardcoded paddingsWarning
Check for reusable components in PodimoBrandbook/PodimoUIWarning

12. View Constants

Move icon configs, magic numbers, strings to private enum Constants at top of view file:

swift
private enum Constants {
    static let iconConfig: BrandbookButtonImageConfig = .icon("icon.name", .left)
    static let maxCount: Int = 10
}

13. Localization

PracticeSeverity
No hardcoded text in viewsCritical
Use "key".localized() patternCritical
Verify keys exist in Localizable.stringsCritical

14. Concurrency

PracticeSeverity
Prefer Swift concurrency (async/await, Task, Actor) over DispatchQueueWarning
Avoid MainActor.run { } - extract to @MainActor functionWarning
No redundant @MainActor on functions when class is annotatedSuggestion

15. Thread Safety

PracticeSeverity
Flag non-thread-safe mutable propertiesCritical
Use actor or @MainActor for shared mutable stateCritical
Mutable static var is unsafeCritical

16. Realm Thread Safety

PracticeSeverity
Realm objects must not cross threadsCritical
Convert to value types before passing to TaskCritical
Don't store Realm objects in properties accessed by multiple threadsCritical
Use ThreadSafeReference or fetch by ID on target threadCritical

17. Error Handling

PracticeSeverity
Avoid try? that swallows errorsWarning
All errors must be caught with do-catch or propagatedWarning
No empty catch { } blocksWarning

18. Swift Best Practices

PracticeSeverity
Use [safe:] for array accessCritical
Implicit returns (no return keyword for single expressions)Suggestion
Success case first in Result switchesSuggestion

19. Memory Management

PracticeSeverity
[weak self] in closures that capture selfWarning
Weak delegatesWarning
Store Combine cancellables in Set<AnyCancellable>Warning

20. Code Safety

PracticeSeverity
No force unwrap (!)Critical
No force cast (as!)Critical
No unsafe array subscripting without [safe:]Critical

21. Code Style

PracticeSeverity
Numbers must have explicit type (CGFloat, Int)Warning
@objc on separate lineSuggestion
Follow SwiftLint rules in .swiftlint.ymlWarning

22. Testability

PracticeSeverity
Protocol-based DI for servicesWarning
// sourcery: AutoMockable on protocolsWarning

23. Unit Tests

PracticeSeverity
Unit tests required for ViewModelsWarning
Unit tests required for ServicesWarning
All cases/branches must be coveredWarning

Review Output Format

Use this format when in Review Mode:

code
## CODE REVIEW: [File/PR name]

### Summary
- Files reviewed: X
- Issues: X critical, X warnings, X suggestions

---

### Critical Issues

**[Issue title]** - `FileName.swift:LINE`
// Current
[problematic code]

// Should be
[corrected code]

---

### Warnings

**[Issue title]** - `FileName.swift:LINE`
// Current
[problematic code]

// Should be
[corrected code]

---

### Suggestions

**[Issue title]** - `FileName.swift:LINE`
[suggestion details]

---

### Summary by Category

| Category | Status |
|----------|--------|
| Architecture | Good / X issues |
| Naming | Good / X issues |
| ... | ... |

### Recommendations
1. [Priority fixes]
2. [...]

### Missing Tests
- [ ] `FeatureViewModelTests.swift` - test file missing
- [ ] `testFetchData_failure` - error case not tested

Severity Legend

SeverityMeaning
CriticalMust fix - crashes, memory leaks, thread safety, security
WarningShould fix - bad practices, maintainability issues
SuggestionNice to have - style, minor improvements