xcode - Swift 中的 "Use of undeclared type",即使类型是内部的,并且存在于同一模块中

标签 xcode swift

我的模块中有一个类型:

import Cocoa

class ColoredDotView : NSView {
   ...
}

它被用在许多不同的类中,没有问题:

class EditSubjectPopoverController : NSObject {

    @IBOutlet internal var subjectColorDotView : ColoredDotView!
    ...
}

但由于某些原因,当我在一个特定类中使用它时,我在类型上出现编译错误:

class EditTaskPopoverController : NSObject {

    @IBOutlet internal var lowPriorityDotView : ColoredDotView! // Error here
    @IBOutlet internal var medPriorityDotView : ColoredDotView! // And here...
    @IBOutlet internal var highPriorityDotView : ColoredDotView! // And here...
    ...
}

编译错误为:

EditTaskPopoverController.swift:15:49: Use of undeclared type 'ColoredDotView'

我不明白。这是文件中的第一个编译错误,其余错误都是第一个错误的症状。此外,没有其他文件存在编译错误。我不明白为什么未声明类型,因为文件在同一个模块中:

enter image description here

我已尝试清理项目、清理构建文件夹并重新启动 Xcode,但均无济于事。哪些潜在的失误会导致 Swift 中出现undeclared type 编译器错误?

最佳答案

对我来说,当我的测试目标没有我的应用程序构建目标在编译源中具有的一些 swift 文件时,我遇到了这个错误。这非常令人困惑,因为“未声明的类型”被用在很多其他地方没有问题,而且错误似乎很模糊。因此,解决方案当然是将包含“未声明类型”的文件添加到测试目标。

关于xcode - Swift 中的 "Use of undeclared type",即使类型是内部的,并且存在于同一模块中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25437891/

相关文章:

ios - 带有 Xcode 6.1.1 的静态库和 cocoapods - ld : library not found Error

swift - Apple 是否从 Swift 1.2 中删除了 bool 值的 &= 运算符?

ios - swift : Sort array by natural order

iphone - 在方向锁定的情况下强制相机在风景中查看

jquery - 使用 UIButton 在 UIWebView 中切换 DIV?

ios - UIPickerView上的EXC_BAD_ACCESS-为什么需要一些指导

ios - iOS XMPP 框架中的自定义 XMPP IQ

ios - 如何在用户默认值中保存多个用户详细信息?

ios - 如何将所有键的 nsdictionary 值插入到 uitableview swift 3.0

ios - 不显示文本字段的底部边框