代码在 Xcode 4 中丢失了语法颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5288697/
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
Code loses syntax color in Xcode 4
提问by MartinMoizard
I have just upgraded to the new Xcode 4and the code is not colored has it ought to be.
我刚刚升级到新的Xcode 4,代码没有着色,它应该是。
For instance, the string NSString
is not colored in my custom code, but when I switch to Apple's code (NSString.h
for example) everything is well colored.
例如,字符串NSString
在我的自定义代码中没有着色,但是当我切换到 Apple 的代码时(NSString.h
例如),一切都很好地着色。
How can I fix that?
我该如何解决?
回答by Alfonso
It's a known bug with the latest XCode. This happens with some projects which are migrated from XCode 3.X to the new version. For some people it seems to help to go to the organizer, and in the project tab delete the derived data for the project where code sense does not work correctly.
这是最新 XCode 的一个已知错误。一些从 XCode 3.X 迁移到新版本的项目会发生这种情况。对于某些人来说,转到组织者似乎有帮助,并在项目选项卡中删除代码感知无法正常工作的项目的派生数据。
If you have a small project, it might also help to create a new project in XCode 4 and import the files from the XCode 3 project.
如果您有一个小项目,在 XCode 4 中创建一个新项目并从 XCode 3 项目导入文件可能也有帮助。
Update:XCode 4.0.1 made the situation a bit better, at least in some of my projects I have syntax coloring and code sense back. But it's still far from fixed.
更新:XCode 4.0.1 使情况好一些,至少在我的一些项目中我有语法着色和代码感觉。但它仍然远未解决。
Update 2:XCode 4.0.2 did not change much. It seems that the problem is related to subprojects, specifically static libraries. According to comments of this blog postsome people were successful by changing header search paths from relative to absolute paths, e.g. instead of Foo/Bar
use $(SOURCE_ROOT)/Foo/Bar
. This together with switching all projects to XCode 3.1 format and to use LLVM 2.0 fixed a lot for me as well. It's not perfect yet, but usable.
更新 2:XCode 4.0.2 没有太大变化。似乎问题与子项目有关,特别是静态库。根据这篇博客文章的评论,有些人通过将标头搜索路径从相对路径更改为绝对路径(例如,而不是Foo/Bar
使用$(SOURCE_ROOT)/Foo/Bar
. 这连同将所有项目切换到 XCode 3.1 格式并使用 LLVM 2.0 也为我解决了很多问题。它还不完美,但可以使用。
Update 3:After converting the sub projects to independent projects and putting them in a workspace(aka the XCode 4 way) I have now full syntax highlighting and code completion back.
更新 3:将子项目转换为独立项目并将它们放入工作区(又名XCode 4 方式)后,我现在拥有完整的语法突出显示和代码完成功能。
My current environment is now a XCode 4 workspace with each projects being 3.1 compatible (as opposed to the default which is 3.2), LLVM GCC 4.2 (system default) and the header search paths are still absolute (using $(SOURCE_ROOT)/.../
).
我当前的环境现在是一个 XCode 4 工作区,每个项目都兼容 3.1(与默认值 3.2 相对)、LLVM GCC 4.2(系统默认值)和标题搜索路径仍然是绝对的(使用$(SOURCE_ROOT)/.../
)。
回答by Jeevanantham Balusamy
I used undefined Macro, But those macros defined in Preprocessor Macros in build settings. So the xcode4 didn't generate any error for that undefined macro.
我使用了未定义的宏,但是在构建设置中的预处理器宏中定义了那些宏。所以 xcode4 没有为那个未定义的宏产生任何错误。
Steps taken to resolve.
解决的步骤。
- Removed undefined macros wherever I used those undefined macros.
- Removed duplicate definitions of Marcos.
- Removed duplicate Resources. (I'd added same (many Thumbs.db files) files into the project.)
- Clean & Build.
- 在我使用这些未定义宏的任何地方删除了未定义的宏。
- 删除了 Marcos 的重复定义。
- 删除了重复的资源。(我在项目中添加了相同的(许多 Thumbs.db 文件)文件。)
- 清洁与建造。
if still you are not getting the color then, please relocate your project to some different location, I changed to my Desktop location.
如果您仍然没有获得颜色,请将您的项目重新定位到其他位置,我更改为我的桌面位置。
After these steps I got the color in my eyes.
经过这些步骤后,我的眼睛里有了颜色。
But its very bad issue. I sucks lot of valuable time. I think these steps may help you.
但它的问题非常糟糕。我浪费了很多宝贵的时间。我认为这些步骤可能对您有所帮助。
Thanks.
谢谢。
回答by marciokoko
I had the same problem with mine. Its a cocos2d game with box and chipmunk. It was a hell of a mess getting the project to recognize and find the user search paths in the first place so I wasn't about to mess with those.
我有同样的问题。它是一个带有盒子和花栗鼠的 cocos2d 游戏。让项目首先识别并找到用户搜索路径真是一团糟,所以我不想弄乱这些。
What I wanted to point out is that I DO HAVE recursive paths and I do have relative paths and I still got the issue. It happened when I added a new version of a 3rd party SDK I was using. It was Testflight 083 which I updagraded to 1.0. I erased my old version but only removed references. Then I manually deleted it from finder. Imported the new SDKv1 folder and readded it to my project and removed the old SDK0 folder path leaving only the newly added SDK1 folder path. For some reason I noticed that even though in v083 I had used a #import in my Prefix.pch file, it still wasn't recognizing a call to a method from AppDelegate. Which means the #import in Prefix.pch for some reason was not working. I had to add #import to my AppDelegate file individually. This gave me duplicate #imports as Jeeva said above. That sounded an alarm in my head.
我想指出的是,我确实有递归路径,而且我确实有相对路径,但我仍然遇到问题。当我添加了我正在使用的第 3 方 SDK 的新版本时发生了这种情况。我升级到 1.0 的是 Testflight 083。我删除了旧版本,但只删除了引用。然后我从finder中手动删除了它。导入新的 SDKv1 文件夹并将其读入我的项目并删除旧的 SDK0 文件夹路径,只留下新添加的 SDK1 文件夹路径。出于某种原因,我注意到即使在 v083 中我在 Prefix.pch 文件中使用了 #import,它仍然无法识别来自 AppDelegate 的方法调用。这意味着 Prefix.pch 中的 #import 由于某种原因不起作用。我不得不将#import 单独添加到我的 AppDelegate 文件中。正如 Jeeva 上面所说,这给了我重复的#imports。
So the solution was to go and effectively remove the duplicate #import in Prefix.pch therefore only leaving the one in AppDelegate. It reindexed and CodeSense works again. Thanks Jeeva!
所以解决方案是去有效地删除 Prefix.pch 中重复的#import,因此只在 AppDelegate 中留下一个。它重新索引并且 CodeSense 再次工作。谢谢杰娃!
回答by creativeandre
This issue was driving me insane, and I had given up hope of fixing it without some ugly hack on XCode's configuration. I passed through this very forum thread a stack overflow of times. Then one day, I happened to accidentally fix it. I'm not sure if you need all these steps, but I've found this a sure-fire way to fix XCode's indexing issues:
这个问题让我发疯,我已经放弃了修复它而不会对 XCode 的配置进行一些丑陋的黑客攻击的希望。我通过这个非常论坛线程堆栈溢出的次数。然后有一天,我碰巧不小心把它修好了。我不确定您是否需要所有这些步骤,但我发现这是修复 XCode 索引问题的可靠方法:
- Clean your project (Command-shift-K)
- Open organizer, close your project.
- Under the "Projects" tab in organizer, remove the derived data for the project you want to reset.
- Quit XCode
In the terminal, run:
sudo mdutil -a -i on
This seems to reset spotlight indexing (I don't know much about it because I don't use spotlight).
- When the command finishes, Spotlight will have to re-index. Look up to see a little dot in the magnifying glass for your spotlight's icon. When the dot leaves, spotlight has re-indexed. You can check the progress by opening spotlight.
- Re-open XCode, and wait for it to re-index all your files.
- Build the project.
- 清理你的项目 (Command-shift-K)
- 打开管理器,关闭您的项目。
- 在管理器中的“项目”选项卡下,删除要重置的项目的派生数据。
- 退出 XCode
在终端中,运行:
sudo mdutil -a -i on
这似乎重置了聚光灯索引(我对此知之甚少,因为我不使用聚光灯)。
- 命令完成后,Spotlight 将不得不重新索引。抬头可以在放大镜中看到聚光灯图标的一个小点。当点离开时,聚光灯已重新索引。您可以通过打开聚光灯来查看进度。
- 重新打开 XCode,等待它重新索引所有文件。
- 构建项目。
On build success, you should now have appropriate syntax highlighting again. I hope you guys find this little discovery as useful as I did :)
构建成功后,您现在应该再次突出显示适当的语法。我希望你们发现这个小发现和我一样有用:)
EDIT:
编辑:
I should probably add that the syntax highlighting sometimes seems to re-break when the debugger hangs the simulator during app launch. I just try to avoid this by being more careful about letting the process hang.
我可能应该补充一点,当调试器在应用程序启动期间挂起模拟器时,语法突出显示有时似乎会重新中断。我只是试图通过更加小心地让进程挂起来避免这种情况。
EDIT2: (sorry first contribution)
EDIT2:(对不起第一次贡献)
Works on XCode 4.6 and 4.6.2.
适用于 XCode 4.6 和 4.6.2。