swift best practices
1
总安装量
0
周安装量
#54912
全站排名
安装命令
npx skills add https://github.com/hoangnguyen0403/agent-skills-standard --skill Swift Best Practices
Skill 文档
Swift Best Practices
Priority: P0
Implementation Guidelines
Control Flow
- Guard for Early Exit: Use
guardover nestediffor better readability. - for-where: Use
for item in items where conditioninstead of nestedif. - Switch Exhaustiveness: Always handle all cases; use
@unknown defaultfor enums.
Value Types & Immutability
- Prefer Structs: Use
structby default; classes only for reference semantics or inheritance. - Immutability: Use
letovervarwhenever possible. - Copy-on-Write: Leverage Swift’s built-in COW for collections.
Naming & Style
- Clear Intent:
isEnabled,hasData,canSubmitfor Booleans. - Avoid Abbreviations:
userRepositorynotuserRepo. - Type Inference: Let compiler infer types unless clarity requires annotation.
Anti-Patterns
- Nested If:
**No Pyramid of Doom**: Use guard. - Mutable Globals:
**No var at Global Scope**: Use constants or dependency injection. - Force Try:
**No try!**: Handle errors properly.