Swift: Use of undeclared type

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-12 14:20:02

问题


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

Use of undeclared type 'myProtocol'

Here is my code:

class LocalContactService: myProtocol{

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


回答1:


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.




回答2:


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




回答3:


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




回答4:


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.

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




回答5:


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

Select the file hit delete and choose the option to Remove Reference

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




回答6:


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



来源:https://stackoverflow.com/questions/38515522/swift-use-of-undeclared-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!