Xcode:代码丢失了语法着色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2138047/
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: code loses syntax coloring
提问by ColorMeFamous
I find that in various situations Objective-C code in Xcode 3.1 (Leopard) can fail to get appropriate syntax coloring after typing or lose coloring that it had.
我发现在各种情况下,Xcode 3.1 (Leopard) 中的 Objective-C 代码在键入后可能无法获得适当的语法着色或丢失它所具有的着色。
This isn't just a "refresh" issue with new custom symbols -- but affects Cocoa framework symbols as well.
这不仅仅是新自定义符号的“刷新”问题——而且还会影响 Cocoa 框架符号。
Sometimes CMD-a to select all text on the code page will make the coloring (re)appear, sometimes double-clicking on a line to select it will work, sometimes I have to add/delete a space in a symbol to get that symbol to (re)color. Rebuilding, or closing/reopening the project may or may not work.
有时 CMD-a 选择代码页上的所有文本会使颜色(重新)出现,有时双击一行选择它会起作用,有时我必须在符号中添加/删除空格才能获得该符号(重新)着色。重建或关闭/重新打开项目可能有效,也可能无效。
Is this a known issue with Xcode? For something so annoying to me, I'm not finding the plentiful discussions of it on SO and elsewhere I'd expect.
这是 Xcode 的已知问题吗?对于对我来说如此烦人的事情,我没有在 SO 和我期望的其他地方找到对它的大量讨论。
And is there any command to force global syntax recoloring?
是否有任何命令可以强制全局语法重新着色?
回答by Lars Schneider
1.) Go to Project --> Build Settings --> Header Search Paths
1.) 转到项目 --> 构建设置 --> 标题搜索路径
2.) Add "$(SRCROOT)/**"
2.) 添加“$(SRCROOT)/**”
3.) Close and reload the project
3.) 关闭并重新加载项目
4.) Go to Xcode --> Window --> Organizer --> Projects --> $YourProject --> Delete Derived Data
4.) 去 Xcode --> Window --> Organizer --> Projects --> $YourProject --> Delete Derived Data
5.) Wait a moment until XCode rebuild all indicies
5.) 稍等片刻,直到 XCode 重建所有索引
To get more information activate verbose logging:
要获取更多信息,请激活详细日志记录:
1.) Increase Xcode log level in Terminal app: defaults write com.apple.dt.Xcode IDEIndexingClangInvocationLogLevel 3
1.) 在终端应用程序中增加 Xcode 日志级别:默认写入 com.apple.dt.Xcode IDEIndexingClangInvocationLogLevel 3
2.) Open Console app. Search for "xcode"
2.) 打开控制台应用程序。搜索“xcode”
3.) I saw "file not found" errors for header files mentioned in the pch file (therefore the fix above)
3.) 我看到 pch 文件中提到的头文件的“找不到文件”错误(因此上面的修复)
回答by rage
I had the same issue with a project that was fine in Xcode 3 and for which the syntax highlighting and code completion has broken in Xcode 4. It took me the better half of the day to figure it out but I found that the following steps will reproduce / fix the issue 100% for me.
我在 Xcode 3 中的一个项目中遇到了同样的问题,并且在 Xcode 4 中语法突出显示和代码完成已损坏。我花了大半天的时间才弄明白,但我发现以下步骤将为我 100% 重现/修复问题。
After trying all the aforementioned solutions to no avail, I tried creating the project from scratch and reimporting every file and folder painstakingly. Every time I imported a couple of files I checked and syntax highlighting still worked. Even after the last few of them it still did. Then I hit build which failed because I forgot to include a couple of common header files in the project .pch file that were there in the old project. And that was when CodeSense broke again.
在尝试了所有上述解决方案都无济于事后,我尝试从头开始创建项目并煞费苦心地重新导入每个文件和文件夹。每次我导入几个文件时,我都会检查和语法突出显示仍然有效。即使在最后几个之后,它仍然如此。然后我点击构建失败,因为我忘记在旧项目中的项目 .pch 文件中包含几个常见的头文件。那是 CodeSense 再次崩溃的时候。
After further investigation we found that if you import a header file that in turn imports the same framework header file than the .pch already does, then CodeSense will break. The same setup did not cause any issues in Xcode 3.
经过进一步调查,我们发现如果您导入一个头文件,而该头文件又导入了与 .pch 相同的框架头文件,那么 CodeSense 将中断。相同的设置在 Xcode 3 中没有引起任何问题。
Example:
例子:
project.pch
项目.pch
#import <Foundation/Foundation.h>
#import "projectConfig.h"
projectConfig.h
项目配置文件
#import <Foundation/Foundation.h>
#import "one.h"
#import "two.h"
So by removing the wholly unnecessary
所以通过删除完全不必要的
#import <Foundation/Foundation.h>
directive from the 'projectConfig.h' you can fix the highlighting and code completion will come back for you as well. If your issue is the same as mine that is.
'projectConfig.h' 中的指令,您可以修复突出显示,代码完成也会为您返回。如果你的问题和我的一样。
回答by Emad
Just select the file who lost the syntax coloring , press Editor > Syntax Coloring > ( choose your language (Objective c++ for ex) instead of 'Default'
只需选择丢失语法着色的文件,按编辑器>语法着色>(选择您的语言(例如Objective c ++)而不是“默认”
回答by todd412
I have found the best way to regain syntax coloring is just to quit Xcode and re-launch it. I couldn't tell you why, but that works every time.
我发现重新获得语法着色的最佳方法就是退出 Xcode 并重新启动它。我不能告诉你为什么,但每次都有效。
回答by Alex Gray
I find that the following will oftendo the trick…
我发现以下内容通常可以解决问题……
"Reselect" both "Base SDK" - and "Architecture" - in "Build Settings". (CLick on blue project icon in top left, while in "Browser mode", aka ?1, then click project settings and mess with the stuff there.
在“构建设置”中“重新选择”“基础 SDK”和“架构”。 (单击左上角的蓝色项目图标,而在“浏览器模式”中,又名?1,然后单击项目设置并处理那里的内容。
Make sure they all line up / it doesn't hurt to do a little toggly-wogglyingup in there, while you're in there… ya know just mix it up a bit. You'll notice xCode has a teensy-tiny mini-stroke - every time you switch between 64 and 32 bit… This is usually when I know if code highlighting is dead for the night, or if I'm good to go.
确保他们都排成一排/在那里做一些摇摆不定的动作不会有什么坏处,而你在那里......你知道只是混合一下。你会注意到 xCode 有一个很小的小笔画 - 每次你在 64 位和 32 位之间切换时......这通常是我知道代码高亮是否在晚上死了,或者我是否可以去的时候。
Often, I will have a project that gets highlighted instantly in 32 bit mode, and just sits there in 64… Who knows.. Ahh, Xcode, you wacky botch.
通常,我会有一个在 32 位模式下立即突出显示的项目,而在 64 位模式下只是坐在那里......谁知道......啊,Xcode,你这个古怪的笨蛋。
回答by Rob Mcelvenny
Select your Project -> Build Settings tab -> Apple LLVM Language 5.0 -> Precompile Prefix Header to YES. NSLog was not highlighting. Currently running Xcode 5.0.1 Hope it helps =) Thanks @rebelzach
选择您的项目 -> Build Settings 选项卡 -> Apple LLVM Language 5.0 -> Precompile Prefix Header 为 YES。NSLog 没有突出显示。目前正在运行 Xcode 5.0.1 希望它有帮助 =) 谢谢@rebelzach
回答by rebelzach
回答by Alex Gray
I can confirm a 100% fix for this problem, based on a question I had asked(and actually answered), as pictured below. One thing i will add is that sometimes it is "errant whitespace" that can also contribute to the loss of highlighting. Either clean it up yourself, or use the Goggle Toolbox for MacXcode 4 plugin, which adds an entry in the XCode Edit
menu called Clean Up Whitespace
.
我可以根据我提出(并实际回答)的问题确认 100%修复此问题,如下图所示。我要补充的一件事是,有时“错误的空白”也会导致突出显示的丢失。要么自己清理它,要么使用Goggle Toolbox for MacXcode 4 插件,它会在 XCodeEdit
菜单中添加一个名为Clean Up Whitespace
.
回答by atlex2
For me it was that I renamed my project, and Teststarget was still pointing to the old pch location, but my App target was pointing to the new one.
对我来说,我重命名了我的项目,而Tests目标仍然指向旧的 pch 位置,但我的 App 目标指向新的位置。
If your app delegate still has code sense, this might be the case for you too. Go into project, select the 'Tests' target search 'prefix' and set it to the equivalent value in the 'app' target.
如果您的应用程序委托仍然具有代码意义,那么您也可能是这种情况。进入项目,选择“测试”目标搜索“前缀”并将其设置为“应用”目标中的等效值。
回答by Cory Kilger
I recently had a similar issue, all coloring and autocomplete stopped working for built-in frameworks, my own classes still worked. Someone recommended to me that I turn off "Run Static Analyzer" in the build settings. It's weird, but it worked.
我最近遇到了类似的问题,内置框架的所有着色和自动完成都停止工作,我自己的类仍然有效。有人建议我在构建设置中关闭“运行静态分析器”。这很奇怪,但它奏效了。