When archiving/building the app which uses SwiftUI for platforms <= iOS 10, the compiler throws errors "Use of undeclared type".
This happens even if the enclosing type is marked as @available(iOS 13.0, *) and also using #if canImport(SwiftUI).
SwiftUI framework is also weakly linked.
Everything works fine if you are running(debug) on an iOS 11+ device, or archiving for a target with minimum supported version <= iOS 11.
This failure occurs because builds with a deployment target earlier than iOS 11 will also build for the armv7 architecture, and there is no armv7 swiftmodule for SwiftUI in the iOS SDK because the OS version in which it was first introduced (iOS 13) does not support armv7 anymore.
I have managed to solve the archiving issue by wrapping the SwiftUI Code/Files in the preprocessor of #if arch(arm64)
.
Example -
#if arch(arm64)
@available(iOS 13.0, *)
struct MyCustomView: View {
var myStrings: [String]
var body: some View {
List {
ForEach(myStrings) { str in
Text(str)
}
}
}
}
#endif
This does disable previews in cases if your deployment target is <= iOS 10. But if used only when archiving, this does work.
If anyone knows of a better solution. Please share.
Adding this answer so that someone in my situation can atleast make it work with SwiftUI.
Cheers!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With