
Swift Language
Write modern, idiomatic Swift 6 core logic—Codable, generics, typed throws, and collection APIs—without leaning on concurrency or SwiftUI skills.
Install
npx skills add https://github.com/dpearson2699/swift-ios-skills --skill swift-languageWhat is this skill?
- If/switch expressions, typed throws (Swift 6+), result builders, and property wrappers
- Opaque vs existential types (some vs any), guard patterns, Never, and Regex builders
- Codable with CodingKeys, custom decoding, and nested containers
- Modern collections (count(where:), contains(where:), replacing()) and FormatStyle formatting
- Explicit pointers to swift-concurrency and swiftui-patterns for adjacent concerns
Adoption & trust: 1.7k installs on skills.sh; 713 GitHub stars; 3/3 security scanners passed (skills.sh audits).
Recommended Skills
Vercel React Native Skillsvercel-labs/agent-skills
Firebase Basicsfirebase/agent-skills
Building Native Uiexpo/skills
Firebase Ai Logic Basicsfirebase/agent-skills
Native Data Fetchingexpo/skills
Firebase Firestorefirebase/agent-skills
Journey fit
Common Questions / FAQ
Is Swift Language safe to install?
skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.
SKILL.md
READMESKILL.md - Swift Language
# Swift Language Patterns Core Swift language features and modern syntax patterns targeting Swift 6.3. Covers language constructs, type system features, Codable, string and collection APIs, formatting, C interop (`@c`), module disambiguation (`ModuleName::symbol`), and performance attributes (`@specialized`, `@inline(always)`). For concurrency (actors, async/await, Sendable), see the `swift-concurrency` skill. For SwiftUI views and state management, see `swiftui-patterns`. ## Contents - [If/Switch Expressions](#ifswitch-expressions) - [Typed Throws](#typed-throws) - [Result Builders](#result-builders) - [Property Wrappers](#property-wrappers) - [Opaque and Existential Types](#opaque-and-existential-types) - [Guard Patterns](#guard-patterns) - [Never Type](#never-type) - [Regex Builders](#regex-builders) - [Codable Best Practices](#codable-best-practices) - [Modern Collection APIs](#modern-collection-apis) - [FormatStyle](#formatstyle) - [String Interpolation](#string-interpolation) - [Common Mistakes](#common-mistakes) - [Review Checklist](#review-checklist) - [References](#references) ## If/Switch Expressions Swift 5.9+ allows `if` and `switch` as expressions that return values. Use them to assign, return, or initialize directly. ```swift // Assign from if expression let icon = if isComplete { "checkmark.circle.fill" } else { "circle" } // Assign from switch expression let label = switch status { case .draft: "Draft" case .published: "Published" case .archived: "Archived" } // Works in return position func color(for priority: Priority) -> Color { switch priority { case .high: .red case .medium: .orange case .low: .green } } ``` **Rules:** - Every branch must produce a value of the same type. - Multi-statement branches are not allowed -- each branch is a single expression. - Wrap in parentheses when used as a function argument to avoid ambiguity. ## Typed Throws Swift 6+ allows specifying the error type a function throws. ```swift enum ValidationError: Error { case tooShort, invalidCharacters, alreadyTaken } func validate(username: String) throws(ValidationError) -> String { guard username.count >= 3 else { throw .tooShort } guard username.allSatisfy(\.isLetterOrDigit) else { throw .invalidCharacters } return username.lowercased() } // Caller gets typed error -- no cast needed do { let name = try validate(username: input) } catch { // error is ValidationError, not any Error switch error { case .tooShort: print("Too short") case .invalidCharacters: print("Invalid characters") case .alreadyTaken: print("Taken") } } ``` **Rules:** - Use `throws(SomeError)` only when callers benefit from exhaustive error handling. For mixed error sources, use untyped `throws`. - `throws(Never)` marks a function that syntactically throws but never actually does -- useful in generic contexts. - Typed throws propagate: a function calling `throws(A)` and `throws(B)` must itself throw a type that covers both (or use untyped `throws`). ## Result Builders `@resultBuilder` enables DSL-style syntax. SwiftUI's `@ViewBuilder` is the most common example, but you can create custom builders for any domain. ```swift @resultBuilder struct ArrayBuilder<Element> { static func buildBlock(_ components: [