Skip to content
Back to skills

Swift Language

ASecurity

Apply Optionals, Protocols, Extensions, and Type Safety patterns in Swift. Use when working with Swift Optionals, Protocols, Extensions, or type-safe APIs.

  • 24 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 4, 2026
documentationswiftapiperformance

Works with

  • api

Security analysis

A100/100

Pro scans all 3 files and shows the line behind each finding

Scanned September 4, 2026

npx -y skills add gabrielmoreira/agent-skills-mirror --skill swift-language --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Swift Language?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Swift Language
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/gabrielmoreira-swift-language/badge)](https://www.skillsdirectory.com/skills/gabrielmoreira-swift-language)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: swift-language
description: Apply Optionals, Protocols, Extensions, and Type Safety patterns in Swift. Use when working with Swift Optionals, Protocols, Extensions, or type-safe APIs.
metadata:
  triggers:
    files:
    - '**/*.swift'
    keywords:
    - protocol
    - extension
    - optional
    - guard
    - enum
---
# Swift Language Standards

## **Priority: P0 (CRITICAL)**

## Implementation Guidelines

### Optionals & Safety

- **Never Force Unwrap**: Use **guard let**, **if let**, or **nil coalescing (??)** to safely unwrap.
- **Nil Comparison**: Use `value != nil` instead of `if let _ = value`.
- **Implicitly Unwrapped**: Avoid `Type!`. Use proper `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: **`extension MyType: MyProtocol { ... }`**. Use extensions for clean code organization, not storage ( **not** use extensions for **stored properties**).
- **Protocol Witnesses**: Explicitly implement all required members to satisfy witness table.

### Type Safety

- **Avoid `Any`**: Use generics or associated types instead for compile-time safety.
- **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 `class` only when **reference identity** necessary or for inheritance. Structs copied; classes shared.

## Anti-Patterns

- **No ! operator**: Use safe unwrapping.
- **No -1 for failure**: Use Optional.
- **No force cast (as!)**: Use conditional cast (as?).

## References

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

## Canonical response anchors

When this skill applies, preserve the following domain terminology or equivalent concrete examples in the answer when relevant:
- Default to struct
- Never force unwrap
- associated values
- value types

- Additional task-grounded exact anchors: extension MyType: MyProtocol; conformance

Files in this skill

  • SKILL.md2.2 KB
  • evals/evals.json3.3 KB
  • references/implementation.md1.4 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in documentation →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.