> swift-best-practices
Standards for Guard, Value Types, Immutability, and Naming. Use when writing idiomatic Swift using guard, value types, immutability, or naming conventions. (triggers: **/*.swift, guard, let, struct, final)
curl "https://skillshub.wtf/HoangNguyen0403/agent-skills-standard/swift-best-practices?format=md"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.
References
> related_skills --same-repo
> typescript-tooling
Development tools, linting, and build config for TypeScript. Use when configuring ESLint, Prettier, Jest, Vitest, tsconfig, or any TS build tooling. (triggers: tsconfig.json, .eslintrc.*, jest.config.*, package.json, eslint, prettier, jest, vitest, build, compile, lint)
> typescript-security
Secure coding practices for TypeScript. Use when validating input, handling auth tokens, sanitizing data, or managing secrets and sensitive configuration. (triggers: **/*.ts, **/*.tsx, validate, sanitize, xss, injection, auth, password, secret, token)
> typescript-language
Modern TypeScript standards for type safety and maintainability. Use when working with types, interfaces, generics, enums, unions, or tsconfig settings. (triggers: **/*.ts, **/*.tsx, tsconfig.json, type, interface, generic, enum, union, intersection, readonly, const, namespace)
> typescript-best-practices
Idiomatic TypeScript patterns for clean, maintainable code. Use when writing or refactoring TypeScript classes, functions, modules, or async logic. (triggers: **/*.ts, **/*.tsx, class, function, module, import, export, async, promise)