All skills

Comprehensive iOS development guidance including Swift best practices, SwiftUI patterns, UI/UX review against HIG, and app planning. Use for iOS code review, best practices, accessibility audits, or planning new iOS apps.

  • 38 files
  • 438.7 KB
  • Updated 3 months ago
  • GitHub

Use this Skill: https://skilld.dev/gh/rshankras/claude-code-apple-skills/ios

This session only. Nothing lands on disk.

coding-best-practicesswift-patterns.md

≈1.3k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Swift Language Patterns

Quick reference for Swift language best practices and idioms.

Optionals Handling

Anti-patterns

// ❌ Force unwrapping
let name = user.userName!

// ❌ Nested if lets (pyramid of doom)
if let user = user {
    if let name = user.userName {
        if let email = user.email {
            // ...
        }
    }
}

// ❌ Unnecessary optional chaining
if expense?.amount != nil {
    let amount = expense!.amount
}

Good patterns

// ✅ Nil coalescing
let name = user.userName ?? "Unknown"

// ✅ Guard for early return
guard let user = expense.payer else { return }

// ✅ Combined guard
guard let user = expense.payer,
      let name = user.userName,
      !name.isEmpty else { return }

// ✅ Optional chaining
let upperName = user?.userName?.uppercased()

Checklist

  • Avoid force unwrapping (!) unless crash is intentional
  • Use optional chaining (?.) and nil coalescing (??)
  • Prefer guard let for early returns
  • Use if let for conditional unwrapping
  • Avoid pyramid of doom with multiple if let

Type Safety & Enums

Anti-patterns

// ❌ String constants
if category == "Food" { }

// ❌ Magic numbers
if status == 0 { }

// ❌ If-else chains for enums
if category == .food {
} else if category == .transport {
} else if category == .entertainment {
}

Good patterns

// ✅ Enum with raw values
enum ExpenseCategory: String, CaseIterable {
    case food = "Food"
    case transport = "Transport"
    case entertainment = "Entertainment"
}

// ✅ Switch with exhaustive checking
switch category {
case .food:
    // ...
case .transport:
    // ...
case .entertainment:
    // ...
}

// ✅ Associated values
enum NetworkResult {
    case success(data: Data)
    case failure(error: Error)
}

Checklist

  • Use enums instead of string/int constants
  • Avoid stringly-typed code
  • Use associated values for related data
  • Prefer switch over multiple if for enums
  • Use CaseIterable when appropriate

Collections & Sequences

Anti-patterns

// ❌ Manual loop for transformation
var names: [String] = []
for user in users {
    names.append(user.name)
}

// ❌ Inefficient filtering
let found = users.filter { $0.id == userId }.first

// ❌ Force array access
let first = array[0]

// ❌ Count comparison
if array.count == 0 { }

Good patterns

// ✅ Map for transformation
let names = users.map { $0.name }

// ✅ CompactMap for optional unwrapping
let names = users.compactMap { $0.userName }

// ✅ First(where:) for finding
let found = users.first { $0.id == userId }

// ✅ Safe array access
guard let first = array.first else { return }

// ✅ isEmpty
if array.isEmpty { }

Checklist

  • Use map, filter, reduce instead of loops where appropriate
  • Prefer compactMap over map + filter nil
  • Use first(where:) instead of filter().first
  • Avoid force-accessing arrays with [0]
  • Use isEmpty instead of count == 0

Error Handling

Anti-patterns

// ❌ Silent failure
try? context.save()

// ❌ Generic error handling
do {
    try something()
} catch {
    print("Error")
}

// ❌ Boolean success flags
func saveData() -> Bool {
    // ...
}

Good patterns

// ✅ Custom errors
enum DataError: LocalizedError {
    case saveFailed
    case invalidData(reason: String)

    var errorDescription: String? {
        switch self {
        case .saveFailed:
            return "Failed to save data"
        case .invalidData(let reason):
            return "Invalid data: \(reason)"
        }
    }
}

// ✅ Proper error propagation
func saveExpense() throws {
    guard !name.isEmpty else {
        throw DataError.invalidData(reason: "Name is empty")
    }
    try context.save()
}

// ✅ Result type
func fetchData(completion: @escaping (Result<Data, Error>) -> Void) {
    // ...
}

Checklist

  • Use Swift error handling (throws, try, catch)
  • Define custom error types
  • Avoid swallowing errors silently
  • Use Result type for async operations
  • Provide meaningful error messages

Naming Conventions

Anti-patterns

// ❌ Unclear names
var e: Expense
func calc() { }
var flg: Bool

// ❌ Redundant names
func calculateCalculation() { }
var nameString: String

// ❌ Poor boolean names
var active: Bool
var valid: Bool

Good patterns

// ✅ Clear names
var currentExpense: Expense
func calculateTotal() { }
var isActive: Bool

// ✅ Descriptive methods
func saveExpense(named: String, amount: Double)
func deleteExpense(_ expense: Expense)

// ✅ Boolean clarity
var isActive: Bool
var hasValidData: Bool
var shouldShowAlert: Bool

Checklist

  • Clear, descriptive names
  • Boolean names start with is, has, should
  • Method names describe action
  • Avoid abbreviations
  • Follow Swift API Design Guidelines

References

Source: SKILL.md on GitHub

No third-party reports yet.

Signed by skilld at 32566aa. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 months ago.

Steadyupdated 3 months ago
What it can do
Reads files Network
last_verified
2026-07-16
review_by
2027-06-22
os_version
iOS 27 / macOS 27
All 4 allowed tools
ReadGlobGrepWebFetch

README badge

README badge for rshankras/claude-code-apple-skills/ios