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

For me, I encountered this error when my test target did not have some swift files that my app build target had in compile sources. It was very confusing because the 'undeclared type' was being used in so many other places with no problem, and the error seemed vague. So solution there was of course to add the file containing the 'undeclared type' to the test target.


This has already been answered by @Craig Otis, but 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.


target membership

Edit

To see the target membership. Select your file then open the file inspector (⌥ + ⌘ + 1) [option] + [command] + 1

detailed description


Phew, finally diagnosed this. Somehow, the offending Swift file EditTaskPopoverController.swift was in two different build phases.

It was in Compile Sources properly, with all the other Swift files, but it was also, for some very strange reason, in the Copy Bundle Resources phase as well, along with all my XIB and image resources.

I have no idea how it got there, but removing it from the extra build phase resolved the issue.

Tags:

Xcode

Swift