'SwiftUI Preview incorrectly tries to build conditional dependency from another platform
SwiftUI Previews are broken for me when one of imported Swift Package has a conditional dependency to another platform.
Steps to reproduce:
- Create Xcode Project with 2 targets. One for macOS, another for iOS.
- Add a Swift Package that has a conditional dependency - eg. depends on another package but only on iOS. Example:
targets: [
.target(name: "Components",
dependencies: [
.productItem(name: "FloatingPanel", package: "FloatingPanel", condition: .when(platforms: [.iOS])),
]),
]
- Try running SwiftUI preview on macOS. It won’t work.
The error I get is no such module UIKit.
It looks like Xcode is trying to build FloatingPanel dependency even though it's condition specifies iOS platform.
Is there any way to fix this?
Solution 1:[1]
Yes, I have the very same issue. Condition works for other platform when building for iOS, but when building for other platrfom iOS dependencies are always included too...
Post on swift forum: https://forums.swift.org/t/swiftpm-platform-conditional-target-dependancy-not-resolved-for-tvos/56767/2
And there are several bug reported...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Gusev Andrey |
