sickn33/agentic-awesome-skills/swift

Claude Code and agent skill by sickn33/agentic-awesome-skills

Trust tier 2
  • community
LLM review pending
Source check pending

Checking that the SKILL.md file is still in the repository.

Language-specific super-code guidelines for swift.

Install

npx vskill@latest install sickn33/agentic-awesome-skills/swift

SKILL.md

Swift: Idiomatic Efficiency Reference

Apply only within the requested scope and current project conventions. Preserve behavior, ownership, error handling, accessibility and security; examples are independent fragments, not equivalent rewrites in every context. Verify language/library versions and run relevant checks. Required tests and user-facing progress/results take precedence over brevity rules. Do not install dependencies or delete files merely to follow these examples.

When to Use

  • Use this skill when the task matches this description: Language-specific super-code guidelines for swift.

Table of Contents

  1. Optionals
  2. Collections & Functional Transforms
  3. Value vs Reference Types
  4. Error Handling
  5. Concurrency
  6. Protocol-Oriented Design
  7. Anti-patterns specific to Swift

1. Optionals {#optionals}

swift
// ❌ Force unwrap
let name = user.name!
// ✅ — guard or if-let
guard let name = user.name else { return }
swift
// ❌ Nested if-let pyramid
if let user = fetchUser() {
if let address = user.address {
if let city = address.city {
display(city)
}
}
}
// ✅ — chained optional binding
if let city = fetchUser()?.address?.city {
display(city)
}
// or guard-let for early exit
guard let city = fetchUser()?.address?.city else { return }
display(city)
swift
// ❌ Ternary for default
let name = user.name != nil ? user.name! : "Unknown"
// ✅
let name = user.name ?? "Unknown"
swift
// ❌ Optional map when if-let is clearer for side effects
user.name.map { display($0) }
// ✅ — map for transforms, if-let for side effects
let upper = user.name.map { $0.uppercased() }
if let name = user.name { display(name) }

2. Collections & Functional Transforms {#collections}

swift
// ❌ Imperative filter + map
var result: [String] = []
for item in items {
if item.isActive { result.append(item.name.uppercased()) }
}
// ✅
let result = items
.filter(\.isActive)
.map { $0.name.uppercased() }
swift
// ❌ Manual dictionary construction
var dict: [String: User] = [:]
for user in users { dict[user.id] = user }
// ✅
let dict = Dictionary(users.map { ($0.id, $0) }, uniquingKeysWith: { _, latest in latest }) // same last-write behavior
// or with possible duplicates:
let dict = Dictionary(grouping: users, by: \.department)
swift
// ❌ Checking isEmpty then accessing first
if !items.isEmpty { process(items[0]) }
// ✅
if let first = items.first { process(first) }
swift
// ❌ Index-based loop
for i in 0..<items.count { process(items[i]) }
// ✅
for item in items { process(item) }
// with index:
for (i, item) in items.enumerated() { process(i, item) }

Use key paths (`\.isActive`) as closure shorthand where supported.


3. Value vs Reference Types {#value-types}

swift
// ❌ Class for plain data (reference semantics where value semantics suffice)
class Point {
var x: Double
var y: Double
init(x: Double, y: Double) { self.x = x; self.y = y }
}
// ✅
struct Point { var x, y: Double }
swift
// ❌ Large struct copied repeatedly (performance hit)
struct HugeData { var buffer: [UInt8] /* thousands of elements */ }
func process(_ data: HugeData) { ... } // Array is copy-on-write; read-only passing need not copy the buffer
// ✅ — use class or pass inout for mutation
func process(_ data: inout HugeData) { ... }
// or use copy-on-write wrapper for large value types

Default to `struct`. Use `class` when you need identity, inheritance, or reference semantics.


4. Error Handling {#errors}

swift
// ❌ Using optionals to mask errors
func parse(_ input: String) -> Data? { ... } // caller doesn't know why it failed
// ✅
func parse(_ input: String) throws -> Data { ... }
swift
// ❌ try! in production code
let data = try! JSONDecoder().decode(User.self, from: jsonData)
// ✅
do {
let data = try JSONDecoder().decode(User.self, from: jsonData)
} catch {
logger.error("decode failed: \(error)")
throw AppError.decodingFailed(underlying: error)
}
swift
// ❌ Generic Error type
enum AppError: Error { case generic(String) }
// ✅ — specific, actionable error cases
enum AppError: Error {
case networkUnreachable
case invalidInput(field: String, reason: String)
case unauthorized
}
swift
// ❌ Catching all errors and ignoring
do { try riskyOperation() } catch { }
// ✅
do {
try riskyOperation()
} catch let error as NetworkError {
handleNetworkError(error)
} catch {
throw error // rethrow unknown
}

5. Concurrency {#concurrency}

swift
// ❌ Callback-based async (pyramid of doom)
fetchUser { user in
fetchPosts(for: user) { posts in
fetchComments(for: posts.first!) { comments in
display(comments)
}
}
}
// ✅ (Swift 5.5+)
let user = try await fetchUser()
let posts = try await fetchPosts(for: user)
guard let firstPost = posts.first else { return }
let comments = try await fetchComments(for: firstPost)
display(comments)
swift
// ❌ Sequential awaits for independent work
let a = try await fetchA()
let b = try await fetchB()
// ✅
async let a = fetchA()
async let b = fetchB()
let (resultA, resultB) = try await (a, b)
swift
// ❌ DispatchQueue.main.async for UI updates in async context
DispatchQueue.main.async { label.text = result }
// ✅
await MainActor.run { label.text = result }
// or mark the function/class @MainActor

Use `actor` for mutable shared state instead of manual locks/queues.


6. Protocol-Oriented Design {#protocols}

swift
// ❌ Deep class inheritance hierarchy
class Animal { ... }
class Dog: Animal { ... }
class GuideDog: Dog { ... }
// ✅ — protocols + composition
protocol Animal { var name: String { get } }
protocol Trainable { func train() }
struct Dog: Animal, Trainable { ... }
swift
// ❌ Protocol with default implementations for everything
protocol Renderable {
func render()
}
extension Renderable {
func render() { /* default */ }
}
// Every conformer uses default — protocol serves no purpose
// ✅ — only default implementations that provide genuine shared logic
swift
// ❌ Associated type when generic parameter suffices
protocol Container {
associatedtype Element
func get() -> Element
}
// ✅ — use `some` or generic parameter for simple cases
func process(_ item: some Equatable) { ... }

7. Anti-patterns specific to Swift {#antipatterns}

Anti-patternPreferred
Force unwrap ! in production codeguard let / if let / ??
try! outside testsdo/catch
class for plain datastruct
Deep inheritance hierarchiesprotocol composition
@objc when pure Swift worksnative Swift types
NSArray / NSDictionaryArray / Dictionary
DispatchQueue in async/await codeactor / MainActor
Implicitly unwrapped optionals as fieldsregular optionals or non-optional with init
Any / AnyObject everywheregenerics with protocol constraints
Massive switch over string valuesenum with raw values
Singleton pattern (global mutable state)dependency injection

Limitations

  • These are language-specific guidelines and do not cover overall architectural decisions.
  • Over-compression might reduce readability; apply judgement.

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewNot runA model review is scheduled for the next rescan.

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
47,054
Repository forks
6,853
7-day trend score
54

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/sickn33/agentic-awesome-skills/swift/badge)](https://verified-skill.com/skills/sickn33/agentic-awesome-skills/swift)

Something wrong with this skill or its page? Tell us.