gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 04:55:24 26 4
gpt4 key购买 nike

我的模块中有一个类型:

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com