Swift: Use of undeclared type

30,170

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.

enter image description here

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

enter image description here

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.

Share:
30,170

Related videos on Youtube

user2924482
Author by

user2924482

Swift Tutorials Begginers

Updated on August 28, 2020

Comments

  • user2924482
    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?

  • user2924482
    user2924482 almost 8 years
    How do I define the protocol?
  • K. Biermann
    K. Biermann almost 8 years
    Here are some examples: developer.apple.com/library/ios/documentation/Swift/Conceptu‌​al/… A basic definition (without any useful content) would be protocol myProtocol {}
  • rr1g0
    rr1g0 over 7 years
    This was exactly my problem! And I had it on the same file, so it wasn't obvious. Thanks
  • Subcreation
    Subcreation over 4 years
    I 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
    ecth over 4 years
    Thanks, 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.