How to make Swift Package Manager package for multiple platforms
Issue #504
https://twitter.com/NeoNacho/status/1181245484867801088?s=20
There’s no way to have platform specific sources or targets today, so you’ll have to take a different approach. I would recommend wrapping all OS specific files in #if os and just having one target. For tests, you could do something similar, one test target, but conditional tests
Every files are in Sources
folder, so we can use platform and version checks. For example Omnia is a Swift Package Manager that supports iOS, tvOS, watchOS, macOS and Catalyst.
For macOS only code, need to check for AppKit and Catalyst
https://github.com/onmyway133/Omnia/blob/master/Sources/macOS/ClickedCollectionView.swift
1 | #if canImport(AppKit) && !targetEnvironment(macCatalyst) |
For SwiftUI feature, need to check for iOS 13 and macOS 10.15
https://github.com/onmyway133/Omnia/blob/master/Sources/SwiftUI/Utils/ImageLoader.swift
1 | 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *) (iOS |