0Pricing
Swift Academy · Lesson

Package.swift: Targets, Products and Dependencies

Anatomy of a Package.swift manifest and defining library and executable products.

Package.swift Overview

Package.swift is the manifest for Swift Package Manager. It declares the package name, Swift version, targets, products, and dependencies.

import PackageDescription
let package = Package(
  name: "MyLibrary",
  platforms: [.iOS(.v16), .macOS(.v13)],
  products: [],
  dependencies: [],
  targets: []
)

Targets

Targets are the basic building blocks: .target (library/executable code) and .testTarget (test code).

.target(
  name: "MyFeature",
  dependencies: [],
  path: "Sources/MyFeature"
),
.testTarget(
  name: "MyFeatureTests",
  dependencies: ["MyFeature"],
  path: "Tests/MyFeatureTests"
)

All lessons in this course

  1. Package.swift: Targets, Products and Dependencies
  2. Local Packages and Feature Modules
  3. Binary Targets and XCFrameworks
  4. Versioning, Resolving Conflicts and Swift Plugins
← Back to Swift Academy