简体   繁体   English

Xcode 8 语法高亮不起作用

[英]Xcode 8 syntax highlighting doesn't work

The code above has correct syntax highlighting in Xcode 7 .上面的代码在Xcode 7 中正确的语法高亮显示 It is mix of Obj-C + Swift:它是 Obj-C + Swift 的混合体:

在此处输入图片说明

I've updated project to support Xcode 8 and only few things was changed:我已经更新了项目以支持Xcode 8,并且只更改了几件事:

  • In Build Settings Swift 2.3 support在构建设置中 Swift 2.3 支持在此处输入图片说明

  • And have fixed few errors related to implicitly unwrapped properties in UIKit并修复了一些与 UIKit 中隐式解包属性相关的错误在此处输入图片说明

After all the project is compiled fine for Xcode 8 .毕竟项目为Xcode 8编译得很好

But Obj-C code integrated in Swift doesn't have any syntax highlighting and vice versa:但是集成在 Swift 中的 Obj-C 代码没有任何语法高亮,反之亦然:

在此处输入图片说明

And there is << error type >> problem with autocomplete:并且自动完成存在<<错误类型>>问题: 在此处输入图片说明

Derived data deleting doesn't help, Xcode restart either :) CocoaPods version 0.38.2, iOS 7删除派生数据无济于事,Xcode 重新启动 :) CocoaPods 0.38.2 版,iOS 7

This answer helped me https://forums.developer.apple.com/thread/46223 with one of my projects:这个答案在我的一个项目中帮助了我https://forums.developer.apple.com/thread/46223

I got help from an apple engineer at WWDC on this issue and resolved it.我从 WWDC 的一位苹果工程师那里得到了这个问题的帮助并解决了它。 The problem stemmed from cocoapods... Apparently cocoapods was copying .h files into the build directory and SourceKit was getting confused.问题源于 cocoapods...显然 cocoapods 正在将 .h 文件复制到构建目录中,而 SourceKit 感到困惑。 I'm not entirely sure why the .h files were being copied - they aren't needed there.我不完全确定为什么要复制 .h 文件-那里不需要它们。 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.因此,如果您有目标,例如 A、B、C 和 C,则未编译这会导致语法突出显示问题。

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.我发现当语法突出显示失败时,在 Xcode 中切换标签可以解决问题¯_(ツ)_/¯ 有时我发现我需要切换到至少 4 个不同的标签才能再次出现。

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.我在使用 Xcode 8 GM 时也发生过这种情况,但在我使用 Xcode 7 时也发生过很多次:有时自动完成功能和语法突出显示会在没有通知的情况下消失。

The only solution that it works for me is restart Xcode but a few times I needed to complete reboot my Mac ;它对我有用的唯一解决方案是重新启动 Xcode,但有几次我需要完成重新启动我的 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 .在 Finder 中,我导航到user->Library->Developer->Xcode->DerivedData Close your Xcode Project then Clear DerivedData.关闭您的 Xcode 项目,然后清除 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.对我来说,由于 Build Phases 下的 Compile Sources 中缺少文件,代码完成/突出显示不起作用。 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.正如上面其他人所说 - 如果我创建一个新选项卡 .. 或 4 然后关闭通常执行的选项卡。 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.我厌倦了使用几个键来完成此操作,并制作了一个简单的 AppleScript 来为我完成此操作。

Create a Automator 'service' and add this script to it.创建一个 Automator“服务”并将此脚本添加到其中。 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!在“键盘”->“快捷方式”->“服务”下的“系统偏好设置”中,找到您的新服务并将其分配给一个空的功能键(我使用 F1),现在您有了 1 键修复!

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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