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
Swift: Use of undeclared type
提问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
回答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
回答by Yonah Karp
Perhaps you've never defined myProtocol
. Or if you have, maybe it's out of scope in the LocalContactService
class
也许您从未定义过myProtocol
. 或者如果你有,也许它超出了LocalContactService
课程的范围
回答by impression7vx
Go to your myProtocol
class, 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
回答by Matthew Harries
I got this error when someone pushed changes that they made to the project.pbxproj
file.
当有人推送他们对project.pbxproj
文件所做的更改时,我收到此错误。
Select the file hit delete
and 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
,然后问题消失了。