I have a Swift package which supports iOS 10, macOS 10.13, tvOS 10 and watchOS 2. I want this package to expose some SwiftUI functionality which could be used when the referencing module can import SwiftUI. For example, making my package type (Persisted
) conform to the SwiftUI protocol DynamicProperty
:
#if canImport(SwiftUI)
import SwiftUI
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
extension Persisted: DynamicProperty { }
#endif
With the above in place, the project no longer builds when building for "Any iOS Device (arm64)" - I get the compiler error:
Cannot find type 'DynamicProperty' in scope
When I change the build target to any iPhone simulator, it builds OK. It also builds OK when building for "Any Mac", "Any tvOS Device", etc. What do I need to do to make the package build for Any iOS?
According to this reddit post, it has to do with the availability of SwiftUI on certain ARM architectures.
The following condition solved the issue for me:
#if canImport(SwiftUI) && (!os(iOS) || arch(arm64))