ios Xcode“使用未声明的标识符”错误,编译/运行得很好
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12150024/
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 "Use of undeclared identifier" errors, compiles/runs just fine
提问by rnystrom
I've got an incredibly annoying issue that is hampering my workflow. In my project I have "User of undeclared identifier" errors all over. They are all in reference to a single class, specifically a Theme class. I checked for any circular referencing with my imports, none. I'm really confused.
我有一个非常烦人的问题,阻碍了我的工作流程。在我的项目中,我到处都是“未声明标识符的用户”错误。它们都参考一个单一的类,特别是一个 Theme 类。我检查了我的导入是否有任何循环引用,没有。我真的很困惑。
Here is a screenshot of the errors. I would post errors in the Build Log for more detail, but there aren't any. It builds and runs just fine...
这是错误的屏幕截图。我会在构建日志中发布错误以获取更多详细信息,但没有任何错误。它构建和运行得很好......
I've tried cleaning, deleting the derived data... Any ideas?
我试过清理,删除派生数据......有什么想法吗?
回答by Newtz
I was having the same problem and noticed that all of the undeclared identifiers were declared in files that were in my pch file.
我遇到了同样的问题,并注意到所有未声明的标识符都是在我的 pch 文件中的文件中声明的。
With this in mind I deleted one of the #import lines from the pch file and recompiled which failed as expected. I then put the deleted line back in, recompiled and it compiled normally with all the false errors gone.
考虑到这一点,我从 pch 文件中删除了 #import 行之一并重新编译,但它按预期失败。然后我将删除的行放回原处,重新编译并正常编译,所有错误错误都消失了。
Hopefully this simple solution helps a few of you out if the above solutions don't.
如果上述解决方案没有帮助,希望这个简单的解决方案可以帮助你们中的一些人。
回答by Richard J. Ross III
These kinds of errors are quite common with Xcode, unfortunately. It would be great if it would auto-refresh its error list all the time, but it doesn't always. When this happens, I strongly suggest that you restart Xcode, which will flush its error cache and hopefully solve your issues.
不幸的是,这些类型的错误在 Xcode 中很常见。如果它会一直自动刷新其错误列表,那就太好了,但并非总是如此。发生这种情况时,我强烈建议您重新启动 Xcode,这将刷新其错误缓存并有望解决您的问题。
回答by user387184
How are you including this class? In most cases I just include the class explicitly in header and/or body - instead of the *.pch file. Then this error goes away in my case.
你如何包括这个类?在大多数情况下,我只是在标题和/或正文中明确包含该类 - 而不是 *.pch 文件。然后这个错误在我的情况下消失了。
Also deleting the derived data workes once in a while. Did you change the location in preferences recently by any chance. I also got this error when I use a ramdisk for derived data and then go back to default. This is the most annoying case - since it causes this error to appear then in almost every file.
偶尔删除派生数据也会起作用。您最近是否有任何机会更改了首选项中的位置。当我将 ramdisk 用于派生数据然后返回默认值时,我也遇到了这个错误。这是最烦人的情况 - 因为它会导致此错误出现在几乎每个文件中。
This error seems to happen more often in Xcode 4.4 than the prior versions.
与之前的版本相比,此错误在 Xcode 4.4 中似乎更常见。
回答by Preethi
Have you included the library files correctly? Take a look at that. Sometimes ARC issues might occur if we don't include the correct file, or something's missing or not connecting UI.
您是否正确包含了库文件?看看那个。有时,如果我们不包含正确的文件,或者缺少某些内容或未连接 UI,则可能会出现 ARC 问题。
回答by tonisives
For me the issue was that I created UnityInterface.h/m file to handle the obj-c to c# interface. UnityInterface.h is already defined by Unity. I renamed my own UnityInterface to _UnityInterface and now everything works.
对我来说,问题是我创建了 UnityInterface.h/m 文件来处理 obj-c 到 c# 接口。UnityInterface.h 已经由 Unity 定义。我将自己的 UnityInterface 重命名为 _UnityInterface,现在一切正常。
回答by Delimiter
Just posting this for anyone who might have this problem later and doesn't find any of these solutions to work: If you have any pragma marked #if statements that only execute if the program is in debug mode it will obviously cause anything declared inside of them to not be declared when you try to archive/export.
只是将这个发布给以后可能遇到这个问题并且没有找到任何这些解决方案工作的人:如果你有任何标记的#if 语句,只有在程序处于调试模式时才执行,它显然会导致任何声明在里面当您尝试存档/导出时不会声明它们。
回答by Sdembla
Might be little late in answering.
回答可能有点晚。
I had this issue very recently. I fix this by updating my OS and then updating Xcode. I tried updating Xcode alone but did not happen because Xcode 9.4 requires OS High Sierra 10.13.*
我最近遇到了这个问题。我通过更新我的操作系统然后更新 Xcode 来解决这个问题。我尝试单独更新 Xcode,但没有发生,因为 Xcode 9.4 需要 OS High Sierra 10.13。*
Happy Updating :)
快乐更新:)
回答by yoAlex5
It it compile time error
它编译时错误
Use of undeclared identifier '<class_name>'
I was run into this issue when developing own framework and app. Objective-C consumer -> Objective-C static framework
我在开发自己的框架和应用程序时遇到了这个问题。Objective-C 消费者 -> Objective-C 静态框架
Report Navigator had a clear description
Report Navigator 有清晰的描述
umbrella header for module '<module_name>' does not include header '<class_name>.h'
The solution was just to add #import <class_name>.h
into umbrella header in a framework target
解决方案只是#import <class_name>.h
在框架目标中添加到伞头中
回答by Denis Kutlubaev
I had the same problem. Closing and opening XCode didn't help.
我有同样的问题。关闭和打开 XCode 没有帮助。
I solved it by checking errors in other targets and fixing them (I had tons of errors in my unit testing target). Also I moved header links from h files to m files. But I'm pretty sure, that the first thing was critical.
我通过检查其他目标中的错误并修复它们来解决它(我的单元测试目标中有大量错误)。我还将标题链接从 h 文件移动到 m 文件。但我很确定,第一件事很关键。
回答by yunhasnawa
For others who experienced the same problem and tried all solution above with no result, perhaps you should try something like I did. I solved the problem simply by unplugging my iPhone USB cable from my Mac and then replugged again those cable. After that, rebuilt again and all undeclared identifier errors were gone.
对于遇到同样问题并尝试了上述所有解决方案但没有结果的其他人,也许您应该像我一样尝试。我只需从 Mac 上拔下 iPhone USB 电缆,然后重新插入那些电缆,就解决了这个问题。之后,再次重建,所有未声明的标识符错误都消失了。