Skills DirectorySkills Directory
SkillsLearnSecurityCategoriesDocsCommunityBlog
Sign InSubmit Skill
Skills Directory

Security-tested agent skills for Claude, coding agents, and AI workflows.

Directory

  • Browse Skills
  • All Skills A–Z
  • Claude Skills
  • Claude Code Skills
  • Agent Skills
  • Categories
  • Authors
  • Submit a Skill

Learn

  • Learn Hub
  • Install Claude Skills
  • Write SKILL.md
  • Skills vs MCP
  • Directories Compared

Security

  • Security
  • Methodology
  • Secure Claude Skills
  • Security Badges

Company

  • About
  • Community
  • Blog
  • API Docs
  • Advertise

2026 Skills Directory. All rights reserved.

ProTermsPrivacyRefunds
Back to skills

Swift Language

ASecurity

Apply modern Swift language patterns to non-SwiftUI, non-concurrency code, including expressions, typed throws, generics, protocols, result builders, property wrappers, opaque and existential types, regexes, and collections. Route concurrency, Codable, formatting, and API naming to their specialist skills.

3 stars
0 votes
0 copies
0 views
Added 9/28/2026
developmentswiftexpressrefactoringapi

Works with

api

Security Analysis

A100/100

Scanned 9/28/2026

Install to Claude Code

$npx -y skills add thiennc-tesoglobal/ios-skills --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 automatically with every re-scan.

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

More formats (shields.io, HTML) on the badges page.

Files
SKILL.md
---
name: swift-language
description: "Apply modern Swift language patterns to non-SwiftUI, non-concurrency code, including expressions, typed throws, generics, protocols, result builders, property wrappers, opaque and existential types, regexes, and collections. Route concurrency, Codable, formatting, and API naming to their specialist skills."
---

# Swift Language Patterns

Apply modern Swift 6.3 syntax and idioms without altering behavior or evaluation order. Route concurrency to `swift-concurrency`, deep serialization to `swift-codable`, formatting to `swift-formatstyle`, naming to `swift-api-design-guidelines`, and SwiftUI state to `swiftui-patterns`.

## Contents

- [Expressions & Control Flow](#expressions--control-flow)
- [Typed Throws (Swift 6+)](#typed-throws-swift-6)
- [Opaque vs Existential Types](#opaque-vs-existential-types)
- [Result Builders & Property Wrappers](#result-builders--property-wrappers)
- [Modern Collections & Regex](#modern-collections--regex)
- [Common Mistakes](#common-mistakes)
- [Review Checklist](#review-checklist)
- [References](#references)

## Expressions & Control Flow

Use value-producing `if` and `switch` expressions for direct assignment, initialization, and single-expression returns:

```swift
// Direct variable initialization from expression
let statusColor = switch order.status {
case .pending: Color.orange
case .completed: Color.green
case .failed: Color.red
}

let badge = if isFeatured { "star.fill" } else { "circle" }
```

Every branch must produce identical value types without multi-statement bodies.

## Typed Throws (Swift 6+)

Specify concrete error types when callers benefit from exhaustive compile-time error handling:

```swift
enum PaymentError: Error {
    case cardExpired, insufficientFunds
}

func processPayment() throws(PaymentError) {
    guard hasFunds else { throw .insufficientFunds }
}

// Caller error handling is exhaustive without casting
do {
    try processPayment()
} catch {
    switch error {
    case .cardExpired: promptNewCard()
    case .insufficientFunds: promptDeposit()
    }
}
```

Use `throws(Never)` for non-throwing conformance in generic protocols. For mixed or open error sources, retain untyped `throws`.

## Opaque vs Existential Types

- **`some Protocol` (Opaque)**: Preferred for return and parameter types. Preserves underlying static type information, enables compiler optimizations, and avoids existential container allocation overhead.
- **`any Protocol` (Existential)**: Use only when dynamic heterogeneous collections or runtime polymorphism is explicitly required (e.g. `[any Plugin]`).

```swift
// Parameter pack / opaque parameter
func render(item: some Displayable) { ... }

// Heterogeneous collection requires existential boxing
let plugins: [any Plugin] = [AudioPlugin(), VisualPlugin()]
```

## Result Builders & Property Wrappers

- **`@resultBuilder`**: Construct declarative DSLs by implementing `buildBlock`, `buildOptional`, and `buildEither`.
- **`@propertyWrapper`**: Encapsulate reusable property storage or validation via `wrappedValue` and projected `projectedValue` (`$`).

```swift
@propertyWrapper
struct Clamped<T: Comparable> {
    var value: T
    let range: ClosedRange<T>

    var wrappedValue: T {
        get { value }
        set { value = min(max(newValue, range.lowerBound), range.upperBound) }
    }
}
```

## Modern Collections & Regex

- Use regex literals `#/pattern/#` with typed capture groups and `RegexBuilder`.
- Leverage Swift collection operations: `contains(where:)`, `allSatisfy`, `min(by:)`, and non-mutating transformations.

## Common Mistakes

- **Defaulting to `any` instead of `some`**: Using `any Protocol` incurs existential boxing costs and suppresses type relationship inference. Prefer `some Protocol`.
- **Overusing typed throws for general errors**: Forcing `throws(MyError)` on functions that wrap URLSession or system APIs requires fragile error translation. Use untyped `throws` for mixed errors.
- **Multi-statement branches in expressions**: `if`/`switch` expressions only evaluate single-expression branches. Multi-line logic requires traditional statements.
- **Forgetting parentheses in function calls**: Wrap expression arguments in parentheses when passing to functions to avoid parsing ambiguity.
- **Modifying evaluation order during refactoring**: When modernizing with expressions, ensure parameter evaluation order remains strictly preserved.

## Review Checklist

- [ ] Value-producing `if`/`switch` used for concise variable initialization
- [ ] `throws(SpecificError)` used only where callers genuinely need exhaustive handling
- [ ] `some Protocol` chosen over `any Protocol` unless heterogeneous storage is required
- [ ] Regex patterns use modern regex literals or `RegexBuilder`
- [ ] Property wrappers maintain thread safety and avoid re-entrant side effects

## References

- Extended patterns and Codable examples: [references/swift-patterns-extended.md](references/swift-patterns-extended.md)
- Attributes and C interop: [references/swift-attributes-interop.md](references/swift-attributes-interop.md)

Attribution

thiennc-tesoglobalthiennc-tesoglobal
View sourceMore from thiennc-tesoglobal →
SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

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

Comments (0)

No comments yet. Be the first to comment!

SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Related Skills

Browser Extension Developer

Use this skill when developing or maintaining browser extension code in the `browser/` directory, including Chrome/Firefox/Edge compatibility, content scripts, background scripts, or i18n updates.

284972 votes

Seo Optimizer

SEO optimization with keyword analysis, readability assessment, technical validation, content quality. Use for search rankings, blog posts, content audits, or encountering keyword density, readability scores, meta tags, schema markup errors.

2222 votes

Google Official Seo Guide

Official Google SEO guide covering search optimization, best practices, Search Console, crawling, indexing, and improving website search visibility based on official Google documentation

1862 votes

Tanstack Start

Build a full-stack TanStack Start app on Cloudflare Workers from scratch — SSR, file-based routing, server functions, D1+Drizzle, better-auth, Tailwind v4+shadcn/ui. Use whenever the user mentions TanStack Start, asks to scaffold a full-stack Cloudflare app with SSR, wants an SSR dashboard, or asks for a React 19 + Cloudflare Workers app with file-based routing and server functions — even if they don't name TanStack Start specifically. No template repo — Claude generates every file fresh per ...

10311 votes

Pentest

PTES-aligned adversarial security audit for backend, frontend, and mobile applications. Produces a CVSS-scored Hacker Report with verified PoCs and phased remediation.

5491 votes
View all in development →