SuperAPI AI Directory

swift

Coding & development

View repository

Updated 10-15 20:31

About this skill

Swift

Model the domain with types; concur with async/await and isolation. UI: swiftui-development. Persistence: swiftdata. Tests: swift-testing. Server: vapor-swift.

Tooling

  • Swift 6 / concurrency checking in new code if the target allows it; respect the app's deployment.
  • SwiftPM or Xcode project — preserve the repo's.
  • swift-format / SwiftLint if they already exist.

Organization

Sources/MyAppCore/
  Models/
  Services/
Tests/MyAppCoreTests/
  • Modules by boundary (MyAppCore vs MyAppUI).
  • internal default; public/package only stable API.
  • Avoid *Kit dumping ground.

Language

  • struct / enum for values; class / actor when there is identity or isolation.
  • enum associated for closed states. switch exhaustive.
  • let default. Explicit mutation (mutating, var local).
  • Domain property wrappers (@Clamped) only with a clear API.
  • Generics with real constraints; some/any aware (any Error vs typed).
  • Sendable on data that crosses isolation; not @unchecked Sendable without an invariant.
struct UserID: Hashable, Sendable {
    var raw: String
}

enum LoadState<Value: Sendable>: Sendable {
    case loading
    case ready(Value)
    case failed(String)
}

Errors

  • throws / Result at the edge. LocalizedError for UI.
  • Do not try! on input/I/O. fatalError only for a programming invariant.
  • Typed errors (enum AuthError) in libs; do not NSError new.

Concurrency

  • async/await to the edge. Task with cancellation (Task.isCancelled / withTaskCancellationHandler).
  • actor for shared mutable state. UI: Isolation MainActor in view model APIs.
  • Avoid DispatchQueue loose in new code if Task solves it.
  • Data races: handle Swift 6 warnings; do not silence with @preconcurrency broad.
  • UI detail: swiftui-development. Thread-safe persistence: swiftdata.

Interop

  • Bridging NS* only at Objective-C edges.
  • nonisolated on Sendable types that do not touch UIKit/AppKit.

Anti-patterns

  • AnyObject + KVO in new code
  • Assume View / SwiftUI in this skill
  • shared mutable singleton without an actor
  • Force unwrap on JSON/network
  • Task.detached to “fix” the compiler

Integration with other skills

  • SwiftUI: swiftui-development
  • macOS: macos-development
  • watchOS: watchos-development
  • SwiftData: swiftdata
  • StoreKit: storekit
  • Widgets: widgetkit
  • Tests: swift-testing
  • MVVM: mvvm-architecture

Completion criteria

  • Clear Sendable types/sealed states
  • async with cancellation at the edges
  • No try! / force unwrap in I/O
  • Honest isolation (MainActor vs domain actor)
  • Tests for the touched core