tl;dr this is currently not possible. See Solution.

Last week, I was working on extracting functionality responsible for handling Live Activities into a separate Swift Package Manager (SPM) package. Apple introduced Live Activities with the release of iOS 16.1. My project’s deployment target is currently set to iOS 13. As you can imagine, this feature had lots of #if available checks.

To make my life a bit easier, I’ve decided to set my package’s deployment target to iOS 16.1. On paper, this (in combination with #if canImport()) would allow me to get rid of all the availability checks spread around my codebase.

The Initial Plan

My plan was to do something like the following:

// Package.swift
let package = Package(
    name: "SportsWidgets",
    platforms: [.iOS("16.1")],
    products: [ /*...*/],
    dependencies: [/*...*/],
    targets: [/*...*/])
// MyProject.app
#if canImport(SportsWidgets) 
import SportsWidgets 
#endif

This sadly doesn’t work as Xcode won’t see your package as one of the available packages.

Solution

The workaround is to fork the dependency, lower the deployment target so that it’s less than or equal to your project’s deployment target and manually convert its deployment targets into @available conditions throughout its source files.

Resources