Swift: Use of undeclared type
Solution 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.
Solution 2
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
Solution 3
Perhaps you've never defined myProtocol
. Or if you have, maybe it's out of scope in the LocalContactService
class
Solution 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
Solution 5
I my case I had to clean the build folder, close the project, run pod install
, and then the issue disappeared.
Related videos on Youtube
Comments
-
user2924482 over 3 years
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?
-
K. Biermann almost 8 yearsHave you declared a protocol "myProtocol"? If so, please show us the declaration. If not, I would recommend you to read developer.apple.com/library/ios/documentation/Swift/Conceptual/…
-
-
user2924482 almost 8 yearsHow do I define the protocol?
-
K. Biermann almost 8 yearsHere are some examples: developer.apple.com/library/ios/documentation/Swift/Conceptual/… A basic definition (without any useful content) would be
protocol myProtocol {}
-
rr1g0 over 7 yearsThis was exactly my problem! And I had it on the same file, so it wasn't obvious. Thanks
-
Subcreation over 4 yearsI ran into this issue while working through this SwiftUI tutorial: developer.apple.com/tutorials/swiftui/handling-user-input and following the steps you provided fixed it. Thanks!
-
ecth over 4 yearsThanks, that solved my issue! Every time this is so insanely unexpected. I am hopping between kotlin and swift all the time and I don't expect such errors from not marking the unit tests. Imo very unintuitive.