简体   繁体   English

Xcode 4代码感不起作用

[英]Xcode 4 code sense is not working

I am running a "old" Xcode 3 project in Xcode 4 and code sense is not working for my own classes. 我在Xcode 4中运行一个“旧的”Xcode 3项目,代码感觉不适用于我自己的类。 I have tried following: 我试过以下:

  • Clean/rebuild 清洁/重建
  • Remove Derived Data 删除派生数据
  • Installing 4.3 documentation 安装4.3文档
  • Restart 重新开始

Without any luck. 没有运气。

Sometimes the code sense works but mostly I just get "No Completions". 有时代码意义有效但主要是我得到“没有完成”。

Try this: 试试这个:

Open Organizer then Project Tab. 打开管理器然后打开项目选项卡

Clear the "Derived Data". 清除“派生数据”。 Xcode should re-index your project then and code sense should work. Xcode应该重新索引你的项目,代码意义应该工作。 At least worked for me. 至少为我工作。

I know this is late, but for reference: http://sealedabstract.com/code/when-xcode-4s-code-completion-autocomplete-breaks/ 我知道这已经晚了,但供参考: http//sealedabstract.com/code/when-xcode-4s-code-completion-autocomplete-breaks/

  • Close the project, leaving XCode still running. 关闭项目,让XCode仍然运行。

  • Open XCode's Organizer window, go to the Projects Tab, select the correct project, and hit the Delete button next to “Derived Data”. 打开XCode的“管理器”窗口,转到“项目”选项卡,选择正确的项目,然后单击“派生数据”旁边的“删除”按钮。

  • Quit XCode. 退出XCode。

  • Navigate to your project's .xcodeproject file in Finder. 在Finder中导航到项目的.xcodeproject文件。 Right-click, choose “Show Package Contents.” 右键单击,选择“显示包内容”。

  • Leave the project.pbxproj file, but delete the project.xcworkspace file, any .pbxuser files, and the entire userdata folder. 保留project.pbxproj文件,但删除project.xcworkspace文件,任何.pbxuser文件和整个userdata文件夹。

  • Open the project in XCode. 在XCode中打开项目。 You will see XCode riding high on the CPU usage for around 10-60 seconds, depending on the size of your project. 您将看到XCode在CPU使用率上高达10-60秒,具体取决于项目的大小。 The activity window will say “Indexing” 活动窗口将显示“索引”

  • When your CPU spike returns to earth, code completion will be working again. 当CPU峰值返回到地时,代码完成将再次起作用。

There's a lot of deleting going on there so please be careful, but this definitely worked for me. 那里有很多删除,所以请小心,但这对我来说肯定有用。

I've been doing this, and it's worked multiple times for me (after trying all of the above previously). 我一直这样做,并且它对我来说多次工作(在完成上述所有操作之后)。

Edit: Now I just hit space, backspace (the mac version) and rebuild... works nice. 编辑:现在我只是命中空格,退格(mac版本)和重建...工作得很好。 Then, remember to scroll (sometimes the colors don't show up until you scroll somewhere) 然后,记得滚动(有时颜色不会显示,直到您滚动到某处)

  1. Find your prefix file: "ProjectName_prefix.pch". 找到您的前缀文件:“ProjectName_prefix.pch”。
  2. Comment out some line. 注释出一些问题。 (basically change it) (基本上改变它)
  3. Build your project, doesn't matter if it fails or not. 构建您的项目,无论是否失败都无关紧要。
  4. Uncomment it. 取消注释。
  5. Build again. 再建一次。

I'm betting only step 2 (modify the prefix) is what does it, but these essentially get you back to running. 我只打赌第2步(修改前缀)就是这样,但这些基本上让你恢复运行。 Suddenly everything magically recolors itself and completes functions. 突然间,一切都神奇地重新回归并完成了功能。

Good luck if that doesn't fix it, perhaps try doing this to your dependency pch files (three20 or FB api's) 祝你好运,如果不解决它,也许尝试这样做你的依赖pch文件(three20或FB api)

Clearing the "Derived Data" only works temporarily for me. 清除“派生数据”仅适用于我。 I have to do it and then restart Xcode like 3-4 times each day to get code sense working again. 我必须这样做,然后每天重启Xcode 3-4次,让代码感觉再次起作用。

I found out the real cause is in the Target's Build Settings. 我发现真正的原因是在Target的 Build Settings中。 I moved everything from Header Search Paths to User Header Search Paths and it is fixed. 我将所有内容从标题搜索路径移动用户标题搜索路径 ,并且已修复。 In my case, the framework I'm working with is RestKit. 就我而言,我正在使用的框架是RestKit。

BTW, I came up with this because I was adding another project ( QuickDialog ) into my project and I was curious that it is using User Header Search Paths , but not Header Search Paths . 顺便说一句,我提出这个是因为我在我的项目中添加了另一个项目( QuickDialog ),我很好奇它正在使用用户头搜索路径 ,而不是头部搜索路径 Here is the difference between them. 这是他们之间的区别。

您可以通过更改构建设置来修复该问题,例如, PreCompile Prefix Headers:NO

FYI, if one file doesn't have code sense but the rest of your project does, check that its added to a target. 仅供参考,如果一个文件没有代码感,但项目的其余部分没有,请检查它是否已添加到目标。 Once I did that I got code sense back in that file. 一旦我这样做,我就会在该文件中获得代码感。

It's been ages but the answer is just to move the code into a new folder and the code sense should be working now. 这已经很久了,但答案只是将代码移动到一个新的文件夹中,代码意义应该现在正在运行。

This happened when I added a new Objective-C Class and the code sense doesn't work only on the newly added .m and .h files (on XCode 4 latest update during this post). 当我添加一个新的Objective-C类并且代码检测不仅对新添加的.m和.h文件(在此帖子中的XCode 4最新更新)上有效时,就会发生这种情况。

Close all xcode windows 关闭所有xcode窗口

Delete all your projects from xcode>window>organizer and restart your project. 从xcode> window> organizer中删除所有项目,然后重新启动项目。 It will now sense and index your project properly. 它现在将正确地感知和索引您的项目。

I wrote about it in detail here . 我在这里详细介绍了它。

Basically my fix was that with localization. 基本上我的修复就是本地化。 I upgraded from xcode 3.2.5 to xcode 4 and then screwed around with built in interface builder and turned on localization for a XIB file accidently which placed my source files in en.lproj directory. 我从xcode 3.2.5升级到xcode 4,然后使用内置的界面构建器搞砸了,并且意外地打开了一个XIB文件的本地化,这将我的源文件放在en.lproj目录中。 After moving them back to Classes folder it worked perfectly. 将它们移回Classes文件夹后,它完美运行。

I open a second project in the background whenever my Xcode's code sensing stops working (it usually works the first time i open the project but after a while code sense no longer works). 每当我的Xcode的代码检测停止工作时,我会在后台打开第二个项目(它通常在我第一次打开项目时工作,但在一段时间后代码检测不再有效)。 So what i do is to open a second project in Xcode. 所以我要做的是在Xcode中打开第二个项目。 Xcode will start indexing the second project and magically the code sense for my main project is back. Xcode将开始为第二个项目编制索引,并且神奇地为我的主项目提供代码意义。

Running Xcode 4.3.1 on Lion 在Lion上运行Xcode 4.3.1

Hope this helps someone. 希望这有助于某人。

From this comment here I was able to debug the problem on my end, it seemed to be a bad -w flag that the clang preprocessor wasn't recognizing properly. 这个评论这里我能够调试我的问题,它似乎是一个坏的-w标志,clang预处理器无法正确识别。 Basically, running 基本上,跑步

defaults write com.apple.dt.Xcode IDEIndexingClangInvocationLogLevel 3

in Terminal increases the verbosity of the indexer, and should help you track down issues. 在终端中增加了索引器的详细程度,并应该帮助您追踪问题。 Open Console.app and look for messages from Xcode, the search string IDEIndexingClangInvocation helped me find them. 打开Console.app并查找来自Xcode的消息,搜索字符串IDEIndexingClangInvocation帮助我找到它们。

For me it happened simply because the file had no target membership. 对我来说,这只是因为该文件没有目标成员资格。 If the first few answers did not work for you, go to your .m file (presumably it's this file that you're having trouble with), open the Utilities view (Edit -> Utilities -> Show File Inspector) and under "Target Membership" check the target to which you want this file to belong. 如果前几个答案对你不起作用,请转到你的.m文件(可能是你遇到问题的这个文件),打开Utilities视图(编辑 - >实用程序 - >显示文件检查器)和“目标”下成员资格“检查您希望此文件所属的目标。

Again, for the sake of helping others with this issue which, in my case, happened upon upgrading to Xcode 4.3. 同样,为了帮助其他人解决这个问题,在我的情况下,在升级到Xcode 4.3时发生了这个问题。

Of course I tried the solutions offered in this post, and none of them worked. 当然,我尝试了这篇文章中提供的解决方案,但没有一个能够奏效。 But the suggestion to move the location of the project in Finder brought back some Code Sense, but the suggestions didn't make any sense. 但是在Finder中移动项目位置的建议带回了一些Code Sense,但这些建议没有任何意义。

I ended up deleting my project and re-cloned it from the git repository .That brougt back Code Sense for me... 我最终删除了我的项目,并从git存储库中重新克隆了它 。这对我来说代码感觉...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM