Agent-skills-standard swift-language
Apply Optionals, Protocols, Extensions, and Type Safety patterns in Swift. Use when working with Swift Optionals, Protocols, Extensions, or type-safe APIs. (triggers: **/*.swift, protocol, extension, optional, guard, enum)
install
source · Clone the upstream repo
git clone https://github.com/HoangNguyen0403/agent-skills-standard
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/HoangNguyen0403/agent-skills-standard "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/swift/swift-language" ~/.claude/skills/hoangnguyen0403-agent-skills-standard-swift-language && rm -rf "$T"
manifest:
skills/swift/swift-language/SKILL.mdsource content
Swift Language Standards
Priority: P0
Implementation Guidelines
Optionals & Safety
- Never Force Unwrap: Use guard let, if let, or nil coalescing (??) to safely unwrap.
- Nil Comparison: Use
instead ofvalue != nil
.if let _ = value - Implicitly Unwrapped: Avoid
. Use properType!
.Type?
Protocols & Extensions
- Protocols as Blueprints: Protocols define blueprint; classes inherit implementation.
- Composition over Inheritance: Prefer protocol composition with structs for better decoupling and performance.
- Extensions: Implement conformance in extension:
. Use extensions for clean code organization, not storage ( not use extensions for stored properties).extension MyType: MyProtocol { ... } - Protocol Witnesses: Explicitly implement all required members to satisfy witness table.
Type Safety
- Avoid
: Use generics or associated types instead for compile-time safety.Any - Enums: Prefer enums with associated values over multiple Optionals. Extract values via switch statement (e.g.,
).case .success(let value): - Value Types: Default to struct for value semantics and thread safety. Use
only when reference identity necessary or for inheritance. Structs copied; classes shared.class
Anti-Patterns
- No ! operator: Use safe unwrapping.
- No -1 for failure: Use Optional.
- No force cast (as!): Use conditional cast (as?).