Skip to content
Back to skills

Swift Package Manager

ASecurity

Swift Package Manager (SPM) for iOS/Swift dependencies - the Package.swift manifest (swift-tools-version, PackageDescription), declaring dependencies with version rules (from, upToNextMinor, exact, ranges, branch/revision), defining targets and products (library/executable), test targets, bundling resources via .process/.copy and Bundle.module, local path packages, and adding packages in Xcode. Use when adding a Swift dependency, creating a reusable Swift package or module, configuring Packag...

  • 16 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added November 11, 2026
developmentswifttestinggitapi

Works with

  • api

Security analysis

A100/100

Scanned November 11, 2026

npx -y skills add TalissonVitorino/kmp-ios-skills --skill swift-package-manager --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Swift Package Manager?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Swift Package Manager
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/talissonvitorino-swift-package-manager/badge)](https://www.skillsdirectory.com/skills/talissonvitorino-swift-package-manager)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: swift-package-manager
description: Swift Package Manager (SPM) for iOS/Swift dependencies - the Package.swift manifest (swift-tools-version, PackageDescription), declaring dependencies with version rules (from, upToNextMinor, exact, ranges, branch/revision), defining targets and products (library/executable), test targets, bundling resources via .process/.copy and Bundle.module, local path packages, and adding packages in Xcode. Use when adding a Swift dependency, creating a reusable Swift package or module, configuring Package.swift, or distributing a KMP XCFramework via SPM. For consuming a KMP shared module (XCFramework/CocoaPods/KMMBridge) use kmp-ios-integration; for testing a package use ios-testing.
---

# Swift Package Manager (SPM)

## Overview

SPM is Apple's dependency manager. A package is defined by a `Package.swift` **manifest** using the `PackageDescription` API: it declares `dependencies`, `targets` (build units), and `products` (what is exported for others to use).

## When to use

- Adding a Swift dependency to an iOS app
- Extracting reusable code into a local Swift package/module
- Configuring `Package.swift`
- Distributing a KMP `XCFramework` via SPM (see kmp-ios-integration)

## Package.swift

```swift
// swift-tools-version: 6.0          ← must be the very first line
import PackageDescription

let package = Package(
    name: "Networking",
    platforms: [.iOS(.v17)],
    products: [
        .library(name: "Networking", targets: ["Networking"]),
    ],
    dependencies: [
        .package(url: "https://github.com/apple/swift-collections.git", from: "1.1.0"),
    ],
    targets: [
        .target(
            name: "Networking",
            dependencies: [
                .product(name: "Collections", package: "swift-collections"),
            ],
            resources: [.process("Resources")]        // asset catalogs/xib auto; others explicit
        ),
        .testTarget(name: "NetworkingTests", dependencies: ["Networking"]),
    ]
)
```

## Version rules

| Rule | Meaning |
|---|---|
| `from: "1.2.0"` | >= 1.2.0, < 2.0.0 (next major) |
| `.upToNextMinor(from: "1.2.0")` | >= 1.2.0, < 1.3.0 |
| `"1.2.0"..<"1.5.0"` | explicit range |
| `.exact("1.2.0")` | pinned |
| `branch: "main"` / `revision: "<sha>"` | track a branch/commit |

## Adding in Xcode / local packages

File → Add Package Dependencies → paste the repo URL → pick a version rule → add the product to your app target. Local package: `.package(path: "../Networking")`.

## Resources

```swift
resources: [
    .process("Media"),       // SPM optimizes (asset catalogs, etc.)
    .copy("config.json"),    // copied verbatim
]
// access inside the package:
let url = Bundle.module.url(forResource: "config", withExtension: "json")
```

## Common mistakes

| Mistake | Fix |
|---|---|
| Missing `swift-tools-version` line | Required as the very first line of `Package.swift` |
| Code in a target not usable | Export it via `products` (`.library`) |
| `Bundle.main` for package resources | Use `Bundle.module` inside a package |
| Resource file not bundled | Declare it under `resources:` (`.process` / `.copy`) |
| API unavailable at runtime | Set `platforms: [.iOS(.v17)]` to match the APIs you use |

## See also

- Consuming a KMP shared module (XCFramework / CocoaPods / KMMBridge): `kmp-ios-integration`
- Testing a Swift package: `ios-testing`

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.