How to Save Gigabytes of Network Traffic and Disk Space Using Swift Package Manager

Many of you have experienced annoying situations - you open a project or switch a branch and see a sad picture of how SPM resolves packages. One of the advantages of CocoaPods over SPM is that dependency checkouts are stored directly with the project in the repository. This allows you to easily start your project from any commit instead of wasting time on CI to download dependencies and resolve them. In this article, I'll show you how to use SPM to store dependency checkouts in a repository, and do it better than CocoaPods.

Before we start, let's define the list of requirements for the future solution:

  • We continue to live in the paradigm of Swift packages
  • External package dependencies become local
  • Need a mechanism for natively cloning external dependencies
  • Store only the files in the dependent repository that are required by the project locally
  • With the input in hand, we can start the implementation.

Let's start by cloning the dependencies. To do this, we'll create a separate local package and add all required dependencies to Package.swift:

// swift-tools-version: 5.7
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "VendorPackages",
    platforms: [
        .iOS(.v15),
        .macOS(.v12),
    ],
    products: [
        .library(
            name: "VendorPackages",
            targets: ["VendorPackages"]
        ),
    ],
    dependencies: [
        .package(
            url: 

Guess you like

Origin blog.csdn.net/iCloudEnd/article/details/131652530