# Swift Language

> Standards for Optionals, Protocols, Extensions, and Type Safety

- Skill: `fierzone/swift-language` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add fierzone/swift-language`
- Raw SKILL.md: https://api.skillmd.com/api/skills/fierzone/swift-language/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: fierzone (https://skillmd.com/u/fierzone)
- Updated: 2026-09-10
- Page: https://skillmd.com/skills/fierzone/swift-language

---


# Swift Language Standards

## **Priority: P0**

## Implementation Guidelines

### Optionals & Safety

- **Never Force Unwrap**: Use `guard let`, `if let`, or nil coalescing (`??`).
- **Nil Comparison**: Use `value != nil` instead of `if let _ = value`.
- **Implicitly Unwrapped**: Avoid `Type!`. Use proper `Type?`.

### Protocols & Extensions

- **Protocol Composition**: Prefer `struct` + protocols over class inheritance.
- **Extensions**: Use for conformance (`extension MyType: Codable`), not storage.
- **Protocol Witnesses**: Explicitly implement all required members.

### Type Safety

- **Avoid `Any`**: Use generics or associated types instead.
- **Enums**: Prefer enums with associated values over multiple Optionals.
- **Value Types**: Default to `struct` unless reference semantics needed.

## Anti-Patterns

- **Force Unwrapping**: `**No ! operator**: Use safe unwrapping.`
- **Sentinel Values**: `**No -1 for failure**: Use Optional.`
- **as! Casting**: `**No Force Cast**: Use conditional cast (as?).`

## References

- [Optionals & Protocols](references/implementation.md)

