Swift Package must set minimum platform version to same as dependency

When you have a dependency on a package with a range of versions, your package must set the supported platform version to the highest iOS version supported by the dependency. Otherwise it might error with something like The package product 'x' requires minimum platform version 16.0 for the iOS platform, but this target supports 15.0

Does anyone know a way around this? We’d like to have a range of versions of the package that support multiple iOS versions.

For example, GoogleMaps 9.4.0 supports iOS 15 and 10.4.0 supports iOS 16. However, my package, which depends on GoogleMaps, must support iOS 16 no matter what version of GoogleMaps it resolves to because it has the potential to resolve to 10.4.0 (and therefore require iOS 16).

If it resolves to GoogleMaps 9.4.0, it builds fine. If it resolves to 10.4.0, it’ll fail with this error:


error: The package product 'GoogleMaps' requires minimum platform version 16.0 for the iOS platform, but this target supports 15.0 (in target 'MyPackage' from project 'MyPackage')

In our particular use case, we want to create a Swift Package that wraps the GoogleMaps SDK and allows the client to control the version of GoogleMaps they use.

Here's a pared-down example Package.swift:

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

import PackageDescription

let package = Package(
  name: "MyPackage",
  platforms: [
    .iOS("15.0")
  ],
  products: [
    .library(
      name: "MyPackage",
      targets: ["MyPackage"]
    )
  ],
  dependencies: [
    .package(
      url: "https://github.com/googlemaps/ios-maps-sdk",
      "9.0.0"..<"11.0.0"
    )
  ],
  targets: [
    .target(
      name: "MyPackage",
      dependencies: [
        .product(
          name: "GoogleMaps",
          package: "ios-maps-sdk"
        )
      ]
    )
  ]
)

Build command:


xcodebuild build -scheme MyPackage -sdk "`xcrun --sdk iphonesimulator --show-sdk-path`" -destination "OS=15.5,name=iPhone 13"

Definitely a hot topic. I can explain how things work now and why. But yes, it can be awkward.

So GoogleMaps has versioned their package correctly. Changing the minimum platform is a major version breaking change. I assume it’s because they’re using some API that is only supported starting with iOS 16 in their newer version. Which means if someone is building it for iOS 15, they would get a compile error.

Essentially for this to work, you would need to have the same semantic versioning for your package and set the appropriate minimum platform version in each of those versions to match GoogleMaps.

2 Likes