Swift: Use of undeclared type

2019-07-05 03:25发布

问题:

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:

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



回答4:

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



回答5:

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