ios Swift:使用未声明的类型

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38515522/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 09:45:13  来源:igfitidea点击:

Swift: Use of undeclared type

iosswiftxcode7protocols

提问by user2924482

I'm implementing a class but I'm getting this error:

我正在实现一个类,但出现此错误:

Use of undeclared type 'myProtocol'

使用未声明的类型“myProtocol”

Here is my code:

这是我的代码:

class LocalContactService: myProtocol{

Any of you knows why I'm getting this error?

你们有人知道为什么我会收到这个错误吗?

回答by Hamed Nova

i had the same error .in my case i found accidentally that i added my swift files into "copy bundle resource" in "build phase" i removed all swift file except assets then everything worked fine.

我有同样的错误。在我的情况下,我意外地发现我在“构建阶段”中将我的 swift 文件添加到“复制包资源”中,我删除了除资产之外的所有 swift 文件,然后一切正常。

enter image description here

在此处输入图片说明

回答by mohsen

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. you can refer to original answer: https://stackoverflow.com/a/30737191/3992606

当有问题的类不属于相同的目标时会导致问题,通常是缺少测试目标。只需确保勾选以下复选框即可。你可以参考原答案:https: //stackoverflow.com/a/30737191/3992606

enter image description here

在此处输入图片说明

回答by Yonah Karp

Perhaps you've never defined myProtocol. Or if you have, maybe it's out of scope in the LocalContactServiceclass

也许您从未定义过myProtocol. 或者如果你有,也许它超出了LocalContactService课程的范围

回答by impression7vx

Go to your myProtocolclass, and on the right side (If you are using XCode), click the Tests of your class. This is what I mean.

转到您的myProtocol班级,然后在右侧(如果您使用的是 XCode),单击您班级的测试。这就是我的意思。

"Use of undeclared type" in Swift, even though type is internal, and exists in same module

在 Swift 中“使用未声明的类型”,即使类型是内部的,并且存在于同一模块中

回答by Matthew Harries

I got this error when someone pushed changes that they made to the project.pbxprojfile.

当有人推送他们对project.pbxproj文件所做的更改时,我收到此错误。

Select the file hit deleteand choose the option to Remove Reference

选择文件命中delete并选择选项Remove Reference

Add the file back to the project, clean (cmd + shift + k), and rebuild

将文件添加回项目,清理(cmd + shift + k),然后重建

回答by Ben

I my case I had to clean the build folder, close the project, run pod install, and then the issue disappeared.

我的情况是我必须清理构建文件夹,关闭项目,运行pod install,然后问题消失了。