Xcode 无法立即识别新类 (iOS)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8300108/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode Not Immediately Recognizing New Classes (iOS)
提问by MillerMedia
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).
我已经使用 Xcode 大约 5 个月了,最近我在添加新类时遇到了一个问题。如果我添加一个新类,例如“CustomCell”,并且我尝试将“#import CustomCell.h”导入到不同的 .m 文件中,它会给我一个错误,提示“未找到 CustomCell.h 文件”,即使它是正确的在名单上。过去我没有遇到过这个问题,我知道在导入时我在做什么(至少我没有改变我以前在它工作时的处理方式)。
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?
我最近不止一次遇到这个问题,有时如果我只是关闭 XCode 并重新启动它,它就会识别这个类。有没有其他人有这个问题?是否有一种快速的方法来刷新项目以查看 Xcode 是否可以识别新类?
回答by TigerCoding
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.
之后,关闭 xcode,重新打开它,打开你的项目,清理它,一切都应该正常工作。
回答by Derek Soike
回答by Umar Farooque
For those dealing with the same issue and the above solution failed to solve it, make sure you don't have the
对于那些处理相同问题而上述解决方案未能解决的人,请确保您没有
issue like i had. It happened with me as i had complex code and i failed to realize my mistake.
像我一样的问题。它发生在我身上,因为我有复杂的代码并且我没有意识到我的错误。
回答by Umar Farooque
I had the same issue with Xcode not seeing any new class I created for a Watch OS2 app I am working on.
我遇到了同样的问题,Xcode 没有看到我为我正在开发的 Watch OS2 应用程序创建的任何新类。
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.
最终我发现它看到了我在“扩展”目录中创建的新类,但是我在项目的“app”目录中创建的每个类都不会显示。
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.
对我有用的是在扩展名中创建一个新的 .swift 文件,然后手动将项目中的引用和实际文件移动到正确的位置。之后,我能够在我的视图控制器中实例化这些类。
Hope that helps any other struggling watch app makers.
希望能帮助任何其他陷入困境的手表应用程序制造商。