Using Swift Packages in all Multiplatform SwiftUI App targets

A little bit of a UI/UX deficiency I’ve found when using Swift Package Manager in Xcode 12 β2 is that adding a Swift package to a multiplatform (iOS/macOS) SwiftUI app requires you to choose a target for the package:

“Add Package to App sheet in Xcode showing a target selection menu”

That means that if you have a platform-agnostic package that you import, and try to use it for both the iOS and macOS targets, you’ll invariably run across an error ("No such module ‘ModuleName’") when you’re writing code against the target you didn’t add it to in the above step, and your project won’t build for that target.

To fix this, Stuart Breckenridge shared the following tip: go to the Build Phases tab for each of your targets, and make sure it’s added under Link Binary with Libraries:

“Target Build Phases settings in Xcode”

Build the app, and you’ll be good to go.

I’ve filed FB8094575 to improve this user flow.

Angelo Stavrow

Montreal, Canada
Email me

Mobile/full-stack developer. Montrealer. Internet gadabout. Your biggest fan.