简体   繁体   中英

Xcode 8 syntax highlighting doesn't work

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:

  • In Build Settings Swift 2.3 support在此处输入图片说明

  • And have fixed few errors related to implicitly unwrapped properties in UIKit在此处输入图片说明

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

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  

Fixed . Problem was related to the presence of target in project which is not compiled. So if you have targets eg A, B, C and C is not compiled this cause problems with syntax highlighting.

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

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.

Build Settings中将Use Legacy Swift Language Version设置YES帮助我解决了类似的问题

评论然后取消评论受影响的行对我有用。

In my case:

In Finder I navigated to user->Library->Developer->Xcode->DerivedData . Close your Xcode Project then Clear DerivedData. It's work for me.

Happy Coding...:)

For me, code completion/highlighting not working due to the missing file in the Compile Sources under Build Phases. I added that file and it works.

Hope this helps anyone.

As others have stated above - if I create a new tab ..or 4 then close the tab that usually does it. Sometimes commenting out a line then immediately uncommenting does the trick as well. I got tired of using several keys to accompolish this and made a simple AppleScript to do it for me.

Create a Automator 'service' and add this script to it. In System Preferences under Keyboard -> Shortcuts -> Services find your new service and assign it to an empty function key (I used F1) and now you have a 1 key fix!

on run {input, parameters}

tell application "Xcode"
    activate
    tell application "System Events" to keystroke "t" using command down
    delay (0.5)
    tell application "System Events" to keystroke "w" using command down
    delay (0.5)
    tell application "System Events" to keystroke "/" using command down
    delay (0.5)
    tell application "System Events" to keystroke "/" using command down
    delay (0.5)
end tell


return input
end run

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM