“未声明类型的使用"在 Swift 中,即使类型是内部的,并且存在于同一个模块中 [英] "Use of undeclared type" in Swift, even though type is internal, and exists in same module

查看:13
本文介绍了“未声明类型的使用"在 Swift 中,即使类型是内部的,并且存在于同一个模块中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的模块中有一个类型:

I have a type in my module:

import Cocoa

class ColoredDotView : NSView {
   ...
}

它在许多不同的类中都没有问题:

It is used in a number of different classes with no issue:

class EditSubjectPopoverController : NSObject {

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

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

But for some reason, when I use it in one specific class, I have compilation errors on the type:

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:未声明类型的使用'彩色点视图'

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

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

Which I don't understand. It's the first compilation error in the file, and the rest of the errors are all symptomatic of the first. Further, there are no other files with compilation errors. I don't understand why the type is undeclared, as the file is in the same module:

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

I have tried cleaning the project, cleaning the build folder, and restarting Xcode, to no avail. What potential missteps can cause an undeclared type compiler error in Swift?

推荐答案

@Craig Otis 已经回答了这个问题,但是问题是当有问题的类不属于相同的目标时导致的,通常测试目标是丢失的.只需确保勾选以下复选框即可.

This has already been answered by @Craig Otis, but the issue is caused when the classes in question do not belong to the same targets, usually the test target is missing. Just make sure the following check boxes are ticked.

查看目标成员资格.选择您的文件,然后打开文件检查器 (⌥ + ⌘ + 1) [option] + [command] + 1

To see the target membership. Select your file then open the file inspector (⌥ + ⌘ + 1) [option] + [command] + 1

这篇关于“未声明类型的使用"在 Swift 中,即使类型是内部的,并且存在于同一个模块中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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