Xcode Not Immediately Recognizing New Classes (iOS

2019-03-24 21:48发布

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?

4条回答
仙女界的扛把子
2楼-- · 2019-03-24 22:19

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.

查看更多
小情绪 Triste *
3楼-- · 2019-03-24 22:24

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.

查看更多
虎瘦雄心在
4楼-- · 2019-03-24 22:29

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.

查看更多
叼着烟拽天下
5楼-- · 2019-03-24 22:30

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

查看更多
登录 后发表回答