xcode 代码感知颜色/完成不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1627033/
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 sense color/completion not working
提问by mga
EDIT:This is weird... if I double-click the Recent Projects item for the project in the welcome screen, code sense and coloring works just fine but if I just click Open
(bottom right in welcome screen) it doesn't. Opening from File > Recent projects
does not work either and neither does double-clicking the .xcodeproj
file in Finder.
编辑:这很奇怪……如果我在欢迎屏幕中双击项目的“最近的项目”项目,代码感知和着色工作得很好,但如果我只是单击Open
(欢迎屏幕右下角),则不会。打开 fromFile > Recent projects
也不起作用,.xcodeproj
在 Finder 中双击文件也不起作用。
Code sense for an iPhone OS 3.0 project I have been working on for several months (through different installations/versions of XCode) is not working any more. For instance, if I do NSString *myString
, all code would be black (no coloring, no Option + Double Click, no code completion). Code Sense only "works" for my own classes/methods/properties but not for any of the SDK classes. If I create a new project from scratch I do have all of these working.
我已经工作了几个月(通过不同的安装/版本的 XCode)的 iPhone OS 3.0 项目的代码意识不再起作用。例如,如果我这样做NSString *myString
,所有代码都是黑色的(没有着色,没有 Option + 双击,没有代码完成)。Code Sense 仅适用于我自己的类/方法/属性,但不适用于任何 SDK 类。如果我从头开始创建一个新项目,我确实可以完成所有这些工作。
I already tried changing the "Base SDK for All Configurations" in this project. I already tried "Rebuild Code Sense Index". I already tried "Clean All Targets".
我已经尝试在这个项目中更改“所有配置的基础 SDK”。我已经尝试过“重建代码感知索引”。我已经尝试过“清除所有目标”。
Documentation in the Preferences is all downloaded and working. For instance, if I select the NSString
above and do Right-Click -> Find text in documentation, I get the window with all the reference to the class.
首选项中的文档全部下载并运行。例如,如果我选择NSString
上面的并执行右键单击 -> 在文档中查找文本,我会得到包含对类的所有引用的窗口。
Any ideas will be greatly appreciated.
任何想法将不胜感激。
采纳答案by Steven Fisher
Get Info on the project in Xcode and change the Project Format to match the version of Xcode you're using (as of this writing, "Xcode 3.2-compatible").
在 Xcode 中获取有关项目的信息并更改项目格式以匹配您正在使用的 Xcode 版本(在撰写本文时,“Xcode 3.2-compatible”)。
You can delete the derived data as well, but unless you've updated your project format the bug will reoccur almost immediately. (It mayhappen even after updating your project format, but I used to have to delete DerivedData several times a day, and I think I've only done it once since fixing the project.)
您也可以删除派生数据,但除非您更新了项目格式,否则该错误几乎会立即再次发生。(即使在更新您的项目格式后也可能发生这种情况,但我曾经每天必须多次删除 DerivedData,而且我想自从修复项目以来我只做过一次。)
As noted elsewhere, switching to LLVM may help. But as I update this answer (2012), you should be using LLVM anyway.
如其他地方所述,切换到 LLVM 可能会有所帮助。但是当我更新这个答案 (2012) 时,无论如何你都应该使用 LLVM。
回答by Arkaaito
In Xcode 4, I haven't been able to find a "Rebuild Code Sense" button either, but if you go to Window -> Organizer, select the Project tab, and click "Delete..." next to the Derived Data folder, it seems to have the same effect. (I got that tip from http://blog.slidetorock.com/xcode-4-code-sense-autocompletion-problems, which indicates that it got it in turn from https://stackoverflow.com/questions/2138047/xcode-code-loses-syntax-coloring- but I don't see it in any of the answers there. Very curious.)
在 Xcode 4 中,我也找不到“Rebuild Code Sense”按钮,但是如果您转到“窗口”->“管理器”,选择“项目”选项卡,然后单击“派生数据”文件夹旁边的“删除...” ,好像效果一样。(我从http://blog.slidetorock.com/xcode-4-code-sense-autocompletion-problems得到了这个提示,这表明它是从https://stackoverflow.com/questions/2138047/xcode依次得到的-code-loses-syntax-coloring- 但我在那里的任何答案中都没有看到它。很好奇。)
回答by karlogeo
Syntax coloring is working back after i do the following steps:
在我执行以下步骤后,语法着色正在恢复:
- Go to Organizer > Project > Delete Derived Data from your current project
- Clean & Build
- Close & Quit XCode, and reopen the project
- Syntax coloring becomes well after project reindexing
- 转到管理器 > 项目 > 从当前项目中删除派生数据
- 清洁与建造
- 关闭并退出 XCode,然后重新打开项目
- 项目重新索引后语法着色变得很好
P.S.
聚苯乙烯
- LLVM Complier 3.0
- i used -fno-objc-arc Complier Flags for all 3rd party libraries(e.g. ASIHTTPRequest)
- My project is created from XCode 4.2
- LLVM 编译器 3.0
- 我将 -fno-objc-arc 编译器标志用于所有 3rd 方库(例如 ASIHTTPRequest)
- 我的项目是从 XCode 4.2 创建的
回答by Sergey Kopanev
Just run in terminal every time when needed
每次需要时只需在终端中运行
rm -fR ~/Library/Developer/Xcode/DerivedData
Works fine. Highlighting and codesense back to me! Sometime needed Make Clean to back it work.
工作正常。高亮和代码感还给我!有时需要 Make Clean 来支持它的工作。
note: as I see it's remove snapshost and another Xcode4 'features'. But we do not use it :)
注意:正如我所见,它删除了 snapshost 和另一个 Xcode4“功能”。但我们不使用它:)
回答by Thomas Müller
I've had the same problem in Xcode 4 and solved it by changing the compiler from GCC 4.2 to LLVM GCC 4.2.
我在 Xcode 4 中遇到了同样的问题,并通过将编译器从 GCC 4.2 更改为 LLVM GCC 4.2 来解决它。
回答by booker
I found a way to avoid this bug. I have seen the bug appears every time I modificate a file which is imported in the prefix.pch.
我找到了避免此错误的方法。我看到每次修改在 prefix.pch 中导入的文件时都会出现该错误。
Try to import your own file on the top of the imported list above UIKit.h and Fonudation.h and NOT at the end as everyone does.
尝试在 UIKit.h 和 Fonudation.h 上方的导入列表顶部导入您自己的文件,而不是像每个人一样在最后。
In my prefix.pch file :
在我的 prefix.pch 文件中:
#ifdef __OBJC__
#import "myFile.h"
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#endif
回答by Felonious CodeMonk
I had this problem as well. I had previously turned off indexing to speed up xcode operations and didn't realize at the time it would stop some of the code highlighting. If you have done this you can turn indexing back on by entering this in terminal:
我也有这个问题。我之前关闭了索引以加速 xcode 操作,当时没有意识到它会停止一些代码突出显示。如果你这样做了,你可以通过在终端中输入以下内容来重新打开索引:
defaults write com.apple.dt.XCode IDEIndexDisable 0
if you want to turn indexing off enter this into terminal:
如果要关闭索引,请在终端中输入:
defaults write com.apple.dt.XCode IDEIndexDisable 1
回答by GnarlyDog
There seems to be a myriad of proposed causes and solutions to this problem, and I think I've tried the majority of them. What finally worked for me (in Xcode 4.1) was to:
对于这个问题,似乎有无数提出的原因和解决方案,我想我已经尝试了其中的大部分。最终对我有用的(在 Xcode 4.1 中)是:
- delete references to the problem files in the project navigator
- move the problem files from the project folder in the Finder
- back in the project navigator, right click and choose Add Files to...
- find the files I had just moved and add them back into the project making sure that "Copy items into destination group's folder (if needed)" was selected.
- 在项目导航器中删除对问题文件的引用
- 从 Finder 中的项目文件夹中移动问题文件
- 回到项目导航器,右键单击并选择将文件添加到...
- 找到我刚刚移动的文件并将它们添加回项目,确保选择了“将项目复制到目标组的文件夹(如果需要)”。
Code Sense restored.
代码感知已恢复。
To be extra specific, my exact issue is when I create a new class via right click in the project navigator, about 30 - 40% of the time code sense does not work in the new class's header file. Interestingly, it does work in the implementation.
更具体地说,我的确切问题是当我通过在项目导航器中右键单击创建一个新类时,大约 30 - 40% 的时间代码感在新类的头文件中不起作用。有趣的是,它确实在实现中起作用。
Things I've tried which failed:
我尝试过但失败的事情:
- deleting derived data folder in the Organizer
- deleting derived data folder in the Finder
- creating a whole new class from scratch (Why this didn't work I have no idea.)
- changing the Syntax Coloring language
- changing the compiler to and from all options multiple times
- specifying a specific Headers Search Path
- 删除管理器中的派生数据文件夹
- 删除 Finder 中的派生数据文件夹
- 从头开始创建一个全新的类(我不知道为什么这不起作用。)
- 更改语法着色语言
- 多次更改编译器和所有选项
- 指定特定的标题搜索路径
I'd love other possible suggestions to put an end to this issue cause it's really annoying!
我喜欢其他可能的建议来结束这个问题,因为它真的很烦人!
回答by drct
Had the same problems in Xcode 4.0.2. Code sense was working in every but two files, one .m file and its corresponding .h file. Tried everything - except rebuilding the code sense index, because I couldn't find the button anywhere - nothing worked. In the end I deleted the correlated files, the .m, .h and the .xib. Created new files, now everthing's working as expected.
在 Xcode 4.0.2 中也有同样的问题。除了两个文件,一个 .m 文件及其相应的 .h 文件中的代码意识都在工作。尝试了一切 - 除了重建代码感索引,因为我在任何地方都找不到按钮 - 没有任何效果。最后我删除了相关文件,.m、.h 和 .xib。创建了新文件,现在一切都按预期工作。
回答by kolinko
In the addition to what tewha did I had to click "Rebuild Code Sense Index" button. It's at the bottom of "General" tab in Get Info on the project.
除了 tewha 之外,我还必须单击“重建代码感知索引”按钮。它位于项目的“获取信息”中“常规”选项卡的底部。