DevPrep

All topics › IDEs & SDK

Dependency managers: CocoaPods, SPM, Carthage?

Middle PRO

Swift Package Manager (the standard)

Apple's and Swift's official tool, built into Xcode and the toolchain (swift build). Dependencies are described in Package.swift (a manifest written in Swift); exact versions are pinned in Package.resolved, which is committed. Xcode adds package references to project.pbxproj, but generates no workspace and needs no external tools. Features: source and binary targets (XCFramework), resources (Bundle.module), build plugins and command plugins (SwiftLint, code generation), package traits (Swift 6.1) for conditional feature compilation, local packages for modularizing an app. Linking is static by default.

// swift-tools-version: 6.0
import PackageDescription

let package = Package(
    name: "Networking",
    platforms: [.iOS(.v17)],
    products: [
        .library(name: "Networking", targets: ["Networking"])
    ],
    dependencies: [
        .package(url: "https://github.com/apple/swift-log.git",
                 from: "1.6.0")
    ],
    targets: [
        .target(
            name: "Networking",
            dependencies: [.product(name: "Logging", package: "swift-log")],
            swiftSettings: [.swiftLanguageMode(.v6)]
        ),
        .testTarget(name: "NetworkingTests", dependencies: ["Networking"])
    ]
)

The rest of this answer, with code and interview follow-ups, is in the DevPrep app.

Read the full answer in DevPrep

Practice this before your interview

DevPrep turns these answers into one-minute challenges: what does this code print, find the bug, mock interviews. One challenge a day.

Get DevPrep on the App Store