Xcode ToolsMidMCQ

What is Swift Package Manager (SPM)?

Test your knowledge:

Explanation & Code

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

Rate your understanding:

Ready to practice more Xcode Tools?

Test yourself with our interactive quiz mode or browse all curated questions for this topic.