19

I've been working with Xcode for about 5 months now and I just recently ran across a problem when I add a new class. If I add a new class, say for example "CustomCell" and I try to import '#import CustomCell.h' into a different .m file it will give me an error saying 'CustomCell.h file not found' even though it's right there on the list. I've had no problem with this in the past and I know what I'm doing when it comes to importing (at least I haven't changed the way I previously went about it when it worked).

I've had this problem more than once recently and sometimes if I just close out XCode and restart it it will recognize the class. Has anyone else had this problem? Is there a quick way to just refresh the project to see if Xcode can recognize the new class?

gcamp
  • 14,622
  • 4
  • 54
  • 85
MillerMedia
  • 3,651
  • 17
  • 71
  • 150

5 Answers5

21

Close all your projects, open the organizer (from the window menu), make sure the correct project is selected, then opposite 'derived data' click delete.

After that, close xcode, re-open it, open your project, clean it, and everything should work okay.

TigerCoding
  • 8,710
  • 10
  • 47
  • 72
18

Multiple Targets: Make sure your file belongs to the necessary targets!


For a new file, make sure the appropriate targets are checked.

xCode Screenshot


For an existing file, check the file inspector to verify target membership.

xCode Screenshot

Derek Soike
  • 11,238
  • 3
  • 79
  • 74
  • This is the correct answer. If your Swift file has multiple target memberships, any class dependencies requires those files to have the same target membership. – Michael N Jan 29 '19 at 14:28
  • 1
    Interesting--I had a view controller in targets and and I added a new view controller that was only in targets . Adding the target to the new view controller based on this answer fixed my problem! – Peter Kaminski Jun 26 '19 at 19:43
1

Fixed, in my case when creating new methods for my class, the other class called test did not see these methods because the target was missing. Thank you

Christian Prada
  • 29
  • 1
  • 1
  • 3
0

For those dealing with the same issue and the above solution failed to solve it, make sure you don't have the

circular import

issue like i had. It happened with me as i had complex code and i failed to realize my mistake.

Community
  • 1
  • 1
0

I had the same issue with Xcode not seeing any new class I created for a Watch OS2 app I am working on.

Eventually I figured out that it saw the new classes I created in the "extension" directory, but that every class I created in the "app" directory of my project would not show.

What worked for me was creating a new .swift file in the extension, then moving both the reference in the project and the actual file manually to the proper location. After that, I was able to instantiate these classes in my view controller.

Hope that helps any other struggling watch app makers.