错误:条件编译标志必须是有效的Swift标识符(而不是“ -sdk”)

时间:2018-12-28 22:04:22

标签: swift xcode sirikit

我试图将 Intents Extension 添加到使用Swift 4和CocoaPods的应用程序(Xcode 10.1)中。

添加 Intents扩展并嵌入到目标(我有两个目标)后,我尝试构建并遇到以下错误:

CompileSwiftSources normal x86_64 com.apple.xcode.tools.swift.compiler
    cd /Users/USER/iOS
    export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer
    export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    export SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.1.sdk
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc -incremental -module-name MyApp_Intents -Onone -enable-batch-mode -enforce-exclusivity=checked -DDEBUG -Onone -enable-bridging-pch -DDEBUG -D -sdk
...
<unknown>:0: error: conditional compilation flags must be valid Swift identifiers (rather than '-sdk')
Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1

这是其他雨燕标志的值:

-Onone -enable-bridging-pch -DDEBUG -D

我已经看过similar issues,但就我而言,编译器抱怨找不到的“ -sdk ”值,我什至尝试了可以从其他Swift标志中删除一些值(并且在绝望中全部删除),但是不幸的是,当我删除它们时,“ 宏名必须是swift的标识符 ”错误。

有人在吗?

1 个答案:

答案 0 :(得分:1)

您的其他Swift Flags条目已过时且格式错误。删除它! (不仅仅是其内容;请删除整个构建设置。)

改为使用活动编译条件;这要容易得多。这是一个现代项目的样子:

enter image description here

您根本不需要-Onone,因为优化级别现在是构建设置。

enter image description here

如果您想使用桥接PCH,现在也有一个构建设置。

enter image description here

您所做的任何事情都不需要使用其他Swift标记,因此请不要使用它们。