Xcode 8.3.3 Bad Syntax Highlighting in C++

Issue

I’ve noticed some rather peculiar syntax highlighting inconsistencies. The class, if, else, while and break keywords are not colorized for some reason. This problem persists even after changing color themes and restarting Xcode. I am using the Civic theme which is one of the defaults in Xcode. The problem seems to be language-specific since this only happens for C++ while it doesn’t for objective-c or Python.

enter image description here

Solution

I’ve found a solution which is far from ideal and from the looks of it, it seems to be an Xcode bug.

  1. Open the Preferences window
  2. Go to the Locations tab
  3. Click on the arrow next to /Users/Library/Developer/Xcode/DerivedData
  4. Go to User Data
  5. Go to FontAndColorThemes
  6. Open any .xccolortheme file with Xcode

    <key>xcode.syntax.identifier.class</key>
    <string>0.115602 0.660894 0.635056 1</string>
    <key>xcode.syntax.identifier.class.system</key>
    <string>0.221291 0.537118 0.556094 1</string> # change this line
    
    <key>xcode.syntax.identifier.function</key>
    <string>0.115602 0.660894 0.635056 1</string>
    <key>xcode.syntax.identifier.function.system</key>
    <string>0.221291 0.537118 0.556094 1</string>
    

The color code for the xcode.syntax.identifier.class.system was not equivalent to that of xcode.syntax.identifier.function.system which caused the class keyword to not be colorized. So the solution is to make them the same. Do the same for all the other keywords.

For a reason which I cannot understand, changing that line for a single color theme automatically fixes this bug for all color themes. Also, I’ve yet to figure out why this bug was language-specific for C++. Nevertheless, the solution works.

Answered By – Senyokbalgul

Answer Checked By – Mary Flores (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.