Xcode 8 syntax highlighting doesn't work
Solution 1
Fixed. Problem was related to the presence of target in project which is not compiled. So if you have targets e.g. A, B, C and C is not compiled this cause problems with syntax highlighting.
Solution 2
This answer helped me https://forums.developer.apple.com/thread/46223 with one of my projects:
I got help from an apple engineer at WWDC on this issue and resolved it. The problem stemmed from cocoapods... Apparently cocoapods was copying .h files into the build directory and SourceKit was getting confused. I'm not entirely sure why the .h files were being copied - they aren't needed there. So the fix was to add a post-build script in your build phases section that removes the headers after a build.
It would look something like this:
function removeHeaders() {
find $BUILD_ROOT/Debug-iphonesimulator/ -name '*.h' -exec rm -f {} \;
}
removeHeaders
Solution 3
I have found that when syntax highlighting falls over, switching tabs in Xcode fixes the issue ¯_(ツ)_/¯ sometimes I find I need to switch to at least 4 different tabs before it comes on again.
Otherwise a quit and reopen
Solution 4
It happened also to me with Xcode 8 GM but also lots of time when I used Xcode 7: sometimes the auto-complete feature and the syntax highlighting die without notice.
The only solution that it works for me is restart Xcode but a few times I needed to complete reboot my Mac; I still don't know exactly what causes this annoying problem.
Solution 5
Commenting and then uncommenting the affected lines worked for me.
Related videos on Youtube
Andrey Banshchikov
I'm an iOS-Developer with 9+ years of experience. I help companies to create mobile apps and I know the whole process from the idea stage to launching the app in AppStore. I have experience working with agile methodologies and collaborating with a development team to release products regularly. Follow Clean Architecture, SOLID principles to write scalable and maintainable code. My goal is to develop high-quality mobile applications, the best in its category. Technologies: Languages: Swift, Objective-C Architectures: VIPER, MVC Frameworks: AVFoundation, StoreKit, AFNetworking(Alamofire), RxSwift, PinLayout, Lottie, linphone, Social Networks (FB, VK, OK) Tests: XCTest, XCUITest WireMock, Postman Analytics: Firebase (Analytics, RemoteConfig), AppsFlyer, Amplitude, Firebase, Appmetrica, e.t.c. Ads: AdColony, Admob, e.t.c. Dependency Management: CocoaPods Continuous Integration: TeamCity Automation: fastlane Inspiration: mikeash.com, WWDC, Uncle Bob, Ray Wenderlich
Updated on June 04, 2022Comments
-
Andrey Banshchikov almost 2 years
The code above has correct syntax highlighting in Xcode 7. It is mix of Obj-C + Swift:
I've updated project to support Xcode 8 and only few things was changed:
After all the project is compiled fine for Xcode 8.
But Obj-C code integrated in Swift doesn't have any syntax highlighting and vice versa:
And there is << error type >> problem with autocomplete:
Derived data deleting doesn't help, Xcode restart either :) CocoaPods version 0.38.2, iOS 7
-
Andrey Banshchikov over 7 yearsRelated to stackoverflow.com/questions/36165865/…
-
-
ymutlu over 7 yearsThanks for the post helped me alot.
-
Endama about 7 years
-
Adrian about 7 yearsFlipping that to
YES
generated a bunch of compiler errors, but flipping it back toNO
, cleaning caches, and rebuilding fixed the autocompletion issue for me. -
Adrian about 7 yearsI encountered this issue when converting a Swift 2.3 syntax project to Swift 3.0. Adding that script resolved the issue for me. My project did not have any CocoaPods in it.
-
Shamsiddin Saidov about 7 yearsHow to add
post-build script
? Is thattarget -> Build Phases tab -> Plus button click -> New Run Script Phase
option click ? -
Adrian about 7 years@Shamsiddin Yes, that's the spot you'll want to put the script. Cut and paste it in there, then press shift+option+command+K to clean caches, then click ctrl+B t rebuild and it should work properly for you after that. If that doesn't do it, try restarting Xcode and re-open your project.
-
TheCodingArt almost 7 yearsAKA, another reason not to use Cocopods
-
Desh__ almost 7 yearsThis is viable option that certainly works. I've yet to find a solution that solves this problem 'correctly' so as a temporary fix, whats the problem? 2 birds with 1 stone.