Browse Questions
  • SPM is Apple's built-in dependency manager for Swift.
  • Unstructured Task { ...
  • The responder chain is a sequence of UIResponder objects that can handle events (touches, key presses, actions).
  • Use a custom URLProtocol subclass that intercepts URLSession requests and returns fake responses — no network needed, tests run instantly.

Answer: SPM is Apple's built-in dependency manager for Swift. It fetches, builds, and links third-party packages directly inside Xcode — no extra tools like CocoaPods or Carthage needed.

How to add a package in Xcode:

  1. File → Add Package Dependencies
  2. Paste the repo URL (e.g. https://github.com/Alamofire/Alamofire)
  3. Choose version rule → Add Package

Creating your own package:

// Package.swift
let package = Package(
    name: "NetworkKit",
    platforms: [.iOS(.v16)],
    products: [
        .library(name: "NetworkKit", targets: ["NetworkKit"])
    ],
    dependencies: [
        .package(url: "https://github.com/Alamofire/Alamofire", from: "5.0.0")
    ],
    targets: [
        .target(
            name: "NetworkKit",
            dependencies: ["Alamofire"]
        ),
        .testTarget(
            name: "NetworkKitTests",
            dependencies: ["NetworkKit"]
        )
    ]
)

Version rules:

  • .exact("5.2.0") — pin to a specific version
  • from: "5.0.0" — any version from 5.0.0 up to the next major (< 6.0.0)
  • .upToNextMinor(from: "5.2.0") — < 5.3.0