Xcode 4.x 中的代码自动完成/语法高亮问题 [英] Issue with code autocompletion / syntax highlighting in Xcode 4.x

查看:21
本文介绍了Xcode 4.x 中的代码自动完成/语法高亮问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的一个项目在 Xcode 中遇到了一个相当奇怪的问题.

I am having a rather strange issue in Xcode on one of my projects.

当我开始编写代码时,我习惯了自动完成为我建议大量条目.出于某种原因,从昨天开始,这已经停止工作.我现在得到奇怪的自动完成条目,例如and"、the"、Andy"、MyCompanyName"等.

When I start to write my code, I am used to the auto-completion suggesting numerous entries for me. For some reason, since yesterday, this has stopped working. I now get strange auto-completion entries such as "and", "the", "Andy", "MyCompanyName" etc.

这种情况以前从未发生过,所以我很困惑为什么现在会发生这种情况,而且只发生在我的一个项目中.我在此站点上搜索了很长时间以查找任何修复程序,并且我尝试清理派生数据,退出 Xcode,从 Xcode 项目中删除工作区和用户文件并重新启动,但这样做后,自动完成工作了一段时间,然后在大约 30 秒的编码后再次中断.

This never happened before and so I am confused as to why it has occurred now, and only on one of my projects. I searched this site for quite some time for any fixes and I've attempted to clean Derived Data, quit Xcode, delete the workspace and user files from the Xcode project and restart, but after doing so, the auto-complete works for a while, then breaks again after about 30 seconds of coding.

有时我可以看到自动完成的解决方案,但只是纯文本(没有类指示符),有时它会完全停止工作.

I can sometimes see auto-complete solutions, but just plain text (no class indicators), then other times it stops working entirely.

有没有其他人遇到过这样的事情并且可以提供一些解决方案?

Has anybody else experienced anything like this and could provide some solution?

推荐答案

我在一个项目中遭受了很长时间的痛苦,该项目不断失去自动完成和语法突出显示.删除派生数据文件夹并重新启动 Xcode 会暂时修复它,最终这几乎变成了肌肉记忆.使用包含多个项目的工作区似乎加剧了我的问题,其中许多项目相互依赖.事实证明,问题出在 clang 索引器上.该项目可以干净地编译,但查看索引器的输出时,它充满了错误.解决所有这些问题解决了我的问题.

I suffered for a long time with a project that kept losing auto-completion and syntax highlighting. Deleteing the Derived Data folder and restarting Xcode would fix it temporarily, and eventually that almost became muscle memory. My problem seemed to be exacerbated by using a workspace that contained multiple projects, many of which were dependant on each other. It turns out the problem was with the clang indexer. The project would compile cleanly, but looking at the output from the indexer it was littered with errors. Fixing ALL these resolved my problems.

在做任何事情之前:确保所有工作区中所有项目中的目标编译干净.这没有任何警告.这对我来说是一个很大的失败——我有一些旧的目标,只是没有干净地编译.其中一些是未使用的,可以删除,另一些是非 ARC,它们使用了已转换为 ARC 的目标中的模块(也转换了这些目标),还有一些只需要修复代码.

BEFORE DOING ANYTHING: make sure ALL the targets in ALL the projects in your Workspace compile cleanly. That's without ANY warnings. This was a big failure on my part - I had old targets that just didn't compile cleanly. Some of these were unused and could be deleted, others were non-ARC that used modules in targets that had been converted to ARC (converted those targets too), and some just needed the code fixing.

一旦您解决了所有这些问题,我们首先需要通过对您的项目进行完整索引来了解索引器的故障所在.

Once you've resolved ALL those problems, the first thing we need to know is where the indexer is failing, by doing a complete index of your project.

  • 首先确保Xcode已关闭,然后打开索引器警告通过在终端中输入消息级别:

  • First, Make sure Xcode is closed, then turn up the indexer warning message level by entering in the Terminal:

 defaults write com.apple.dt.Xcode IDEIndexingClangInvocationLogLevel 3

  • 然后找到您的项目/工作区的派生数据文件夹(可能是~/Library/Developer/Xcode/DerivedData/您的项目名称-一些胡言乱语),然后将其删除(但保持派生数据文件夹处于打开状态,因为您可能需要返回并执行几次.

  • Then find the Derived Data folder for your project/workspace (probably ~/Library/Developer/Xcode/DerivedData/your project name-some gibberish), and delete it (but keep the Derived Data folder open because you'll probably have to go back and do this a few times.

    接下来,打开控制台应用并单击清除显示,并将过滤器设置为IDE"以仅显示我们感兴趣的消息.

    Next, open the Console app and click Clear Display, and set the filter to "IDE" to only show the messages we're interested in.

    最后,打开 Xcode 和导致问题的项目/工作区,您会看到控制台开始填满消息.

    Finally, open Xcode and the project/workspace that's causing your problems, and you'll see the console start to fill up with messages.

    要查找错误,请将控制台过滤器更改为错误:" - 我们的目标是将这些错误减少到零.

    To look for errors, change the Console filter to "error:" - our aim is to reduce these to zero.

    我发现的大多数错误都缺少头文件.Xcode 本身似乎比索引器更智能.它似乎能够从索引器无法找到并包含来自其他项目的头文件.

    The majority of errors I found were missing header files. Xcode itself seems to be smarter than the indexer. It seems to be able to find and include header files from other projects that the indexer can't.

    因此,在您看到致命错误:'somefile.h' 文件未找到"的任何地方,请确保将该文件的路径添加到用户标题搜索路径 在目标的构建设置中.我发现这样做的最好方法是双击该字段以获取弹出窗口,然后将文件夹从查找器拖到其中.这会添加一个新条目,但假设它在同一个工作区中,它会添加一个相对文件路径(这对于您将来移动工作区文件夹很重要).如果同一个项目有多个目标,则可以在项目级别而不是目标级别设置搜索路径,并将目标搜索路径设置为$(inherited).

    So, anywhere you see "fatal error: 'somefile.h' file not found", make sure you add the path of that file to the User Header Search Paths in the target's build settings. The best way I've found to do this is to double click on the field to get the popup, and drag the folder from the finder into it. This adds a new entry, but assuming it's in the same workspace, it adds a relative file path (this is important in case you move your workspace folder in the future). If you've got multiple targets for the same project, you can set the search path at the project rather than target level, and set the target search paths to $(inherited).

    您可能在使用库或框架时遇到类似问题 - 再次更新适当的搜索路径.

    You might have similar problems with Libraries or Frameworks - again, update the appropriate search path.

    一旦你修复了一些错误,关闭 Xcode,清除控制台,删除项目的派生数据,打开 Xcode 并让它再次索引.

    Once your fixed some errors, close Xcode, clear the console, delete the project's Derived Data, open Xcode and let it index again.

    重复,直到所有错误都消失.

    Repeat until all your errors are gone.

    一旦你在这个好地方,代码自动完成和语法高亮应该像魅力一样工作:)

    Once you're in this good place, code autocomplete and syntax highlighting should work like a charm :)

    这篇关于Xcode 4.x 中的代码自动完成/语法高亮问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆