Xcode 8 语法高亮不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39598543/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 09:17:51  来源:igfitidea点击:

Xcode 8 syntax highlighting doesn't work

iosobjective-cswiftxcodesyntax-highlighting

提问by Andrey Banshchikov

The code above has correct syntax highlightingin Xcode 7. It is mix of Obj-C + Swift:

上面的代码在Xcode 7 中正确的语法高亮显示。它是 Obj-C + Swift 的混合体:

enter image description here

在此处输入图片说明

I've updated project to support Xcode 8and only few things was changed:

我已经更新了项目以支持Xcode 8,只有很少的事情发生了变化:

  • In Build Settings Swift 2.3 support enter image description here

  • And have fixed few errors related to implicitly unwrapped properties in UIKit enter image description here

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

  • 并修复了一些与 UIKit 中隐式展开属性相关的错误 在此处输入图片说明

After all the project is compiled finefor Xcode 8.

毕竟项目为Xcode 8编译得很好

But Obj-C code integrated in Swift doesn't have any syntax highlightingand vice versa:

但是集成在 Swift 中的 Obj-C 代码没有任何语法高亮,反之亦然:

enter image description here

在此处输入图片说明

And there is << error type >>problem with autocomplete: enter image description here

并且自动完成存在<<错误类型>>问题: 在此处输入图片说明

Derived data deleting doesn't help, Xcode restart either :) CocoaPods version 0.38.2, iOS 7

删除派生数据无济于事,Xcode 重新启动 :) CocoaPods 0.38.2 版,iOS 7

采纳答案by Andrey Banshchikov

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.

固定的。问题与未编译的项目中存在目标有关。因此,如果您有目标,例如 A、B、C 和 C 未编译,则会导致语法突出显示问题。

回答by Andrey Banshchikov

This answer helped me https://forums.developer.apple.com/thread/46223with 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. 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:

我从 WWDC 的一位苹果工程师那里得到了这个问题的帮助并解决了它。问题源于 cocoapods...显然 cocoapods 正在将 .h 文件复制到构建目录中,而 SourceKit 感到困惑。我不完全确定为什么要复制 .h 文件-那里不需要它们。所以修复是在你的构建阶段部分添加一个构建后脚本,在构建后删除标题。
它看起来像这样:

function removeHeaders() {  
    find $BUILD_ROOT/Debug-iphonesimulator/  -name '*.h' -exec rm -f {} \;  
}  
removeHeaders  

回答by Daniel Galasko

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

否则退出并重新打开

回答by Massimo Polimeni

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 Xcodebut a few times I needed to complete reboot my Mac; I still don't know exactly what causes this annoying problem.

它对我有用的唯一解决方案是重新启动 Xcode,但有几次我需要完成重新启动我的 Mac;我仍然不知道究竟是什么导致了这个烦人的问题。

回答by Andrey Volobuev

Setting Use Legacy Swift Language Versionto YESin the Build Settingshelped me to solve similar issue

设置使用旧式斯威夫特语言版本,以构建设置帮我解决类似的问题,

回答by guptron

Commenting and then uncommenting the affected lines worked for me.

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

回答by Renish Dadhaniya

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.

在 Finder 中,我导航到user->Library->Developer->Xcode->DerivedData。关闭您的 Xcode 项目,然后清除 DerivedData。这对我有用。

Happy Coding...:)

快乐编码...:)

回答by Desh_

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.

正如上面其他人所说 - 如果我创建一个新选项卡 .. 或 4 然后关闭通常执行此操作的选项卡。有时注释掉一行然后立即取消注释也能解决问题。我厌倦了使用多个键来完成此操作,并制作了一个简单的 AppleScript 来为我完成此操作。

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!

创建一个 Automator“服务”并将此脚本添加到其中。在“键盘”->“快捷方式”->“服务”下的“系统偏好设置”中,找到您的新服务并将其分配给一个空的功能键(我使用 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