SwiftUI-在低于或等于iOS 10的部署目标上使用“使用未声明的xxx类型" [英] SwiftUI - “Use of undeclared type xxx” on deployment targets below or equal to iOS 10

查看:30
本文介绍了SwiftUI-在低于或等于iOS 10的部署目标上使用“使用未声明的xxx类型"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在存档/构建使用SwiftUI的平台< = iOS 10的应用程序时,编译器会引发错误使用未声明的类型".

When archiving/building the app which uses SwiftUI for platforms <= iOS 10, the compiler throws errors "Use of undeclared type".

即使将封闭类型标记为@available(iOS 13.0,*)并使用#if canImport(SwiftUI),也会发生这种情况.

This happens even if the enclosing type is marked as @available(iOS 13.0, *) and also using #if canImport(SwiftUI).

SwiftUI框架之间也存在弱链接.

SwiftUI framework is also weakly linked.

如果您在iOS 11+设备上运行(调试),或者归档最低支持版本< = iOS 11的目标,一切都可以正常工作.

Everything works fine if you are running(debug) on an iOS 11+ device, or archiving for a target with minimum supported version <= iOS 11.

推荐答案

之所以会发生此故障,是因为使用早于iOS 11的部署目标进行的构建也会针对armv7架构进行构建,并且iOS SDK中没有用于SwiftUI的armv7 swiftmodule.因为首次引入该操作系统的版本(iOS 13)不再支持armv7.

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.

通过将SwiftUI代码/文件包装在 #if arch(arm64)的预处理器中,我设法解决了归档问题.

I have managed to solve the archiving issue by wrapping the SwiftUI Code/Files in the preprocessor of #if arch(arm64).

示例-

#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

如果您的部署目标是< = iOS 10,这会禁用预览.但是,如果仅在存档时使用,则可以使用.

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.

添加此答案,以便我所处的环境至少可以使它与SwiftUI一起使用.

Adding this answer so that someone in my situation can atleast make it work with SwiftUI.

干杯!

这篇关于SwiftUI-在低于或等于iOS 10的部署目标上使用“使用未声明的xxx类型"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆