Issue with code autocompletion / syntax highlighting in Xcode 4.x

后端 未结 8 1381
说谎
说谎 2020-11-28 05:49

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

When I start to write my code, I am used to the auto-completion suggesting numerous entries for me

相关标签:
8条回答
  • 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.

    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.

    • 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
      
    • 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.

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

    • 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.

    • 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.

    • 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.

    • 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 :)

    0 讨论(0)
  • 2020-11-28 06:26

    Deleting only the Derived Data of the project that is failing is not enough

    I had to delete all Derived Data of all projects, did a Clean project and restart Xcode

    Amazing

    0 讨论(0)
提交回复
热议问题