Swift/Xcode 奇怪的行为 : "Use of undeclared type" error shown in case of struct used before declaration

标签 swift xcode

目前我在 swift 项目和 Playground 上看到 Xcode 的奇怪行为

enter image description here

但这就像工作:

enter image description here

有人能解释一下这是什么原因吗?

转载于playground和swift 5.1项目

最佳答案

在屏幕 1 中,settingsDb 变量在全局命名空间中声明,在这种情况下声明顺序很重要,因此必须在使用之前声明所有类型的顶级声明。

如果需要更多详细信息,请查找“swift top-level”,developer.apple.com 官方博客为 here

关于Swift/Xcode 奇怪的行为 : "Use of undeclared type" error shown in case of struct used before declaration,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59509241/

相关文章:

ios - 无法在 Xcode 控制台中从 Objective-C 记录 Swift 单例

swift - 使用 Swift Joint 执行 2 个并行网络请求

iphone - MFMessageComposeViewController:如何限制以蜂窝消息而不是 iMessage 的形式发送消息

objective-c - Xcode 中的链接错误

ios - NSURLConnection不返回任何数据

ios - 在 Mac OS X 10.6 上安装 Xcode 3.2.5

ios - swift/iOS : Capture only the previous 10 seconds of a video recording

swift - 直接使用或在字符串插值中使用时返回不同值的字符串属性

swift - 使用 RxSwift 限制对服务类的并发访问

ios - 我已停止 captureSession 但扫描仪仍在工作。如何解决这个错误?