Xcode 显示许多错误,但程序编译并运行良好(在模拟器和设备中)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12023484/
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 shows many errors but program compiles and runs fine (in both simulator and device)
提问by Julian
After installing the CocoaLumberHyman' log compressor class I've been getting this annoying behavior: Xcode complains that there are many undeclared identifiers and gives me many errors (not warnings but errors with the red icon).
安装 CocoaLumberHyman 的日志压缩器类后,我遇到了这种烦人的行为:Xcode 抱怨有很多未声明的标识符并给我很多错误(不是警告,而是带有红色图标的错误)。
The thing is that I can compile and run my iPad app just fine but Xcode won't do any autocompletion. I tried cleaning the build folder (Product > option+ Clean), and also deleting derived data. I've also rebooted to no avail.
问题是我可以很好地编译和运行我的 iPad 应用程序,但 Xcode 不会做任何自动完成。我尝试清理构建文件夹(产品 > option+ 清理),并删除派生数据。我也重启了也没用。
As you can imagine this is a pain to work with. I did have this behavior happen before on a previous version of Xcode; it had something to do with stuff in my precompiled headers file but using the solution above would always fix it. I'm currently using Xcode 4.4 (4F250).
正如您可以想象的那样,这是一种痛苦的工作。我之前在以前版本的 Xcode 上确实发生过这种行为;它与我预编译的头文件中的内容有关,但使用上面的解决方案总是可以解决它。我目前使用的是 Xcode 4.4 (4F250)。
Sample error I'm getting:
我得到的示例错误:
Semantic Error: use of undeclared identifier 'DDTTYLogger'
Semantic Error: use of undeclared identifier 'DDTTYLogger'
The above happens even with classes that I wrote myself and that have not changedsince installing the CocoaLumberHyman compressor class.
即使是我自己编写的类也会发生上述情况,并且自安装 CocoaLumberHyman 压缩器类以来没有改变。
回答by Julian
I finally solved this after MANY attempts using the following:
经过多次尝试,我终于解决了这个问题:
Remove the last #import from my Prefix.pch and build again. Errors would happen (obviously). Put the line back and build again. No errors would show and after 10 seconds or so, errors would come back again.
从我的 Prefix.pch 中删除最后一个 #import 并重新构建。错误会发生(显然)。将线放回并重新构建。不会显示任何错误,10 秒左右后,错误会再次出现。
Repeat the above except instead of the last #import, remove the last TWO imports, then three, four, etc. I did this until I removed five imports and when I put them back and waited, Xcode stopped complaining.
重复上述操作,而不是最后一个#import,删除最后两个导入,然后是三个、四个等等。我这样做直到我删除了五个导入,当我把它们放回去等待时,Xcode 停止抱怨。
Note that this didn't occur to me at all. I read this solution on a blog somewhere.
请注意,这对我来说根本没有发生。我在某个地方的博客上阅读了这个解决方案。
Weird bug...
奇怪的错误...
回答by Yunus Nedim Mehel
Open build settings and set "Precompile Prefix Header" to "No", that solved my problem.
打开构建设置并将“预编译前缀头”设置为“否”,这解决了我的问题。
Kudos for: https://stackoverflow.com/a/7035492/936957
回答by Ben Baron
I've been running into these issues constantly on all the latest versions of Xcode, in both Objective-C and Swift.
我在所有最新版本的 Xcode 上不断遇到这些问题,包括 Objective-C 和 Swift。
I noticed today that I was getting the errors in one particular class file. I removed it from some extra targets it was in and the errors finally went away!
我今天注意到我在一个特定的类文件中收到错误。我从它所在的一些额外目标中删除了它,错误终于消失了!
I think Xcode has some fundamental bugs with it's handling of multiple targets right now. My theory is that if the other target is not built, you will essentially see errors from that target. Anyway hope this helps someone.
我认为 Xcode 现在在处理多个目标方面存在一些基本错误。我的理论是,如果未构建另一个目标,您基本上会看到来自该目标的错误。无论如何希望这可以帮助某人。
回答by alphaplus
This problem can cause by setting "Target Membership" for some files are not the same.
此问题可能是由于某些文件的“目标成员身份”设置不同而导致的。
Example:
示例:
A class XYZ put in file "a.swift" and it's used in file "b.swift". But "Target Membership" setting of "a.swift" is not the same "Target Membership" setting of b.swift.
XYZ 类放在文件“a.swift”中,并在文件“b.swift”中使用。但是“a.swift”的“Target Membership”设置与b.swift 的“Target Membership”设置不同。
Check "Target Membership" setting as below:
检查“目标会员”设置如下:
回答by iDeveloper
Not bad, If you follow these Steps-
不错,如果您按照以下步骤操作-
1-Clean Xcode(Cmd+Shif+K).
1-清理Xcode(Cmd+Shif+K)。
2- Clear Derived Data(Cmd+Shift+G).
2- 清除派生数据(Cmd+Shift+G)。
Enter this path( ~/Library/Developer/Xcode/DerivedData/).
输入此路径( ~/Library/Developer/Xcode/DerivedData/)。
3- Quit and open again Xcode.
3-退出并再次打开Xcode。
回答by Adam
I was having issues with a library installed via cocoapods
. Going to Build Settings
and searching for 'Allow Non-modular Includes In Framework Modules' then setting it to Yes
did the trick.
我在通过cocoapods
. 转到Build Settings
并搜索“允许非模块化包含在框架模块中”,然后将其设置为可以解决问题Yes
。
回答by Aviram Netanel
I had it on Xcode 10.1 when I accidentally pressed:
当我不小心按下时,我在 Xcode 10.1 上有它:
Cmd+Shift+U- ( build for Testing)
Cmd+Shift+U- (为测试构建)
try Clean (Cmd+Shift+K) and then:
尝试清理 (Cmd+Shift+K) 然后:
Cmd+Shift+R( build for Running)
Cmd+Shift+R(为运行构建)
回答by Tom Howard
Open up a terminal and create a nice little function accessible via the command line...
打开一个终端并创建一个可以通过命令行访问的不错的小函数......
nano ~/.bashrc
nano ~/.bashrc
add (making the necessary substitutions between the pointy braces)
添加(在尖括号之间进行必要的替换)
cycle() {
git stash save "BACKUP"
git checkout <<SOME OTHER BRANCH>>
git branch -D
xcodebuild -allowProvisioningUpdates -workspace <<YOUR WORKSPACE>>.xcworkspace -scheme <<YOUR SCHEME>> -configuration Release clean
git checkout
}
^X
and save it by following the prompts, then enter source ~/.bashrc
to make it visible to the current terminal session.
^X
并按照提示保存它,然后输入source ~/.bashrc
以使其对当前终端会话可见。
Make sure your branch is pushed to origin, cause we're going to delete it :)
确保你的分支被推送到原点,因为我们要删除它:)
Call the function using cycle <<MY BRANCH>>
(once it's run you might want to call git stash pop
to restore any working copy changes)
调用函数使用cycle <<MY BRANCH>>
(一旦它运行,你可能想要调用git stash pop
来恢复任何工作副本更改)
Hope it works for you! Xcode, get on your game!
希望这对你有用!Xcode,开始你的游戏吧!
回答by AivanF.
After update to Xcode 11, I met the same problem. I tried all the mentioned advices (cleaning folders, turning on/off different settings, restarting xCode), but nothing helped. Also, I have a big project in C, so, I'd like to keep using precompiled headers.
更新到 Xcode 11 后,我遇到了同样的问题。我尝试了所有提到的建议(清理文件夹、打开/关闭不同的设置、重新启动 xCode),但没有任何帮助。另外,我有一个 C 语言的大项目,所以,我想继续使用预编译的头文件。
Finally I found that simple restart of Mac OSsolves the problem! It's really weird behaviour, but I'm happy anyway that I found a solution – it's hard to code when lots of colourful error messages float around.
最后我发现简单的重启 Mac OS 就解决了这个问题!这真的是很奇怪的行为,但无论如何我很高兴我找到了一个解决方案——当大量五颜六色的错误消息四处飘散时,很难编码。
回答by nteissler
Running on Xcode Version 10.1 (10B61), I set the build setting "Increase Sharing of Precompiled Headers" to NO
. I was working in an .xcworkspacewith many projects sharing the same frameworks, and no Objective-C bridging header (meaning I've added no obj-c code myself). I'm not sure when Xcode did away with .pchfiles by default, but I didn't have any of those in my project.
在 Xcode 版本 10.1 (10B61) 上运行,我将构建设置“增加预编译头文件的共享”设置为NO
. 我在一个.xcworkspace中工作,其中有许多项目共享相同的框架,并且没有 Objective-C 桥接头(这意味着我自己没有添加 obj-c 代码)。我不确定 Xcode何时默认取消 .pch文件,但我的项目中没有任何这些文件。