All skills
dpearson2699 avatar

/ios-networking

@cf3fe87

Build, review, or improve networking code in iOS/macOS apps using URLSession with async/await, structured concurrency, and modern Swift patterns. Use when working with REST APIs, downloading files, uploading data, WebSocket connections, pagination, retry logic, request middleware, caching, background transfers, or network reachability monitoring. Also use when handling HTTP requests, API clients, network error handling, or data fetching in Swift apps.

Use this Skill: https://skilld.dev/gh/dpearson2699/swift-ios-skills/ios-networking

This session only. Nothing lands on disk.

referenceslightweight-clients.md

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

Lightweight Clients (Closure-Based)

Use this pattern to keep networking or service dependencies simple and testable without introducing a full view model or heavy DI framework. It works well for SwiftUI apps where you want a small, composable API surface that can be swapped in previews/tests.

Intent

  • Provide a tiny "client" type made of async closures.
  • Keep business logic in a store or feature layer, not the view.
  • Enable easy stubbing in previews/tests.

Minimal shape

struct SomeClient {
    var fetchItems: (_ limit: Int) async throws -> [Item]
    var search: (_ query: String, _ limit: Int) async throws -> [Item]
}

extension SomeClient {
    static func live(baseURL: URL = URL(string: "https://example.com")!) -> SomeClient {
        let session = URLSession.shared  // Prototyping only. For production, create a URLSession with timeoutIntervalForRequest: 30, timeoutIntervalForResource: 300, waitsForConnectivity: true, and a URLCache.
        return SomeClient(
            fetchItems: { limit in
                // build URL, call session, decode
            },
            search: { query, limit in
                // build URL, call session, decode
            }
        )
    }
}

Usage pattern

@MainActor
@Observable final class ItemsStore {
    enum LoadState { case idle, loading, loaded, failed(String) }

    var items: [Item] = []
    var state: LoadState = .idle
    private let client: SomeClient

    init(client: SomeClient) {
        self.client = client
    }

    func load(limit: Int = 20) async {
        state = .loading
        do {
            items = try await client.fetchItems(limit)
            state = .loaded
        } catch {
            state = .failed(error.localizedDescription)
        }
    }
}
struct ContentView: View {
    @Environment(ItemsStore.self) private var store

    var body: some View {
        List(store.items) { item in
            Text(item.title)
        }
        .task { await store.load() }
    }
}
@main
struct MyApp: App {
    @State private var store = ItemsStore(client: .live())

    var body: some Scene {
        WindowGroup {
            ContentView()
                .environment(store)
        }
    }
}

Guidance

  • Keep decoding and URL-building in the client; keep state changes in the store.
  • Make the store accept the client in init and keep it private.
  • Avoid global singletons; use .environment for store injection.
  • If you need multiple variants (mock/stub), add static func mock(...).

Pitfalls

  • Don't put UI state in the client; keep state in the store.
  • Don't capture self or view state in the client closures.

Source: SKILL.md on GitHub

No alerts17d4 checks · Risk SAFE
  • Gen Agent Trust Hub17d

    The skill provides secure patterns for iOS and macOS networking using URLSession and Network.framework. It correctly identifies security best practices, such as using Keychain for tokens and avoiding force-unwraps. A low-risk surface for indirect prompt injection exists as the skill facilitates fetching external data.

  • Socket17d

    No alerts

  • Snyk17d

    Risk: LOW · No issues

  • ZeroLeaks5mo

    1 finding · Score: 82/100

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

Last checked against GitHub 2 days ago.

Steadyupdated 3 months ago
  • ios
  • urlsession
  • async-await
  • networking
  • swift
  • rest-api
  • http
  • error-handling
  • pagination

README badge

README badge for dpearson2699/swift-ios-skills/ios-networking

Handles REST APIs, file downloads/uploads, WebSockets, pagination, retry logic, and network reachability in iOS/macOS apps using URLSession with async/await and structured concurrency. Covers API client architecture, request middleware, token refresh, error handling, and App Transport Security configuration for Swift 6.3+.

Generated from the current SKILL.md.

Does this skill work with iOS versions before iOS 15?
No. The skill targets iOS 15+ because URLSession's native async/await overloads were introduced in iOS 15. It explicitly does not cover completion-handler variants used in older code.
Does this skill cover third-party networking libraries like Alamofire?
No. The skill focuses exclusively on URLSession with async/await and structured concurrency. It does not require or discuss third-party dependencies.
What Swift version does this skill target?
Swift 6.3. All examples use modern Swift patterns including structured concurrency and Sendable conformance.
Does this cover WebSocket connections?
The skill description mentions WebSocket connections as a use case, but the provided content does not include WebSocket implementation details — only URLSession patterns for HTTP requests, downloads, uploads, and streaming.
Should I use URLSession.shared or create a custom session?
Use URLSession.shared only for simple, one-off requests. Production code should create a configured URLSession with custom timeout intervals, cache policies, and headers.

Generated from the current SKILL.md. These answers refresh after source changes.