So I’ve had countless issues with the Xcode syntax coloring in the past. I’ve been able to fix them through various trials and each solution is different from the next. This time, I can trace the problem to a specific event so I am wondering if others have had this problem and know of a solution.
My syntax coloring was just fine until I did a ‘git pull’ from the terminal. After the pull, only one method was completely broken while the rest of my code was partially colored correctly. By partial I mean objects and methods were being colored the same color (which they shouldn’t) but it was better than nothing, right? Well, to fix this I decided to close the project and delete my derived data then reopen the project. After reopening, the coloring is completely broken.
Has anyone had this problem after pulling from git?
I fixed it! What ended up working for me was the following:
Deleted the line
#import <opencv/cv.h>in .pch file because it was being imported on every class that was using it, therefore this import was redundant.Deleted the line
#import <Foundation/Foundation.h>from one of my .h files. This line was already contained in my .pch file so this extra import was redundant.Added the line
#import <UIKit/UIKit.h>to the top of your files “ApplicationDelegate.h” and “main.mm”. I previously only had it in my “ViewController.h” and .pch files.Saved files and closed Xcode.
In Finder, went to Users/~/Library/Developer/Xcode/DerivedData/ and deleted the folder associated with my project.
Reopened Xcode and the project and waited for it to “reindex”.
Success!
It seems redundant #imports between your .pch file and other header files in your project can break the syntax coloring. A good way to see if this might be the problem is just delete the contents of your .pch file temporarily and see if that alone fixes the issue. If so, you may have some redundant #imports.