You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为Swift Package单独指定macOS最低版本且不影响其他平台兼容性?

解决方法

你不需要手动列出所有平台,只需在platforms数组里单独指定macOS的最低版本即可,其他未声明的平台会自动使用Swift Package Manager的默认最低版本:

platforms: [
    .macOS(.v10_14)
]

如果仍有编译警告,可在使用NLLanguageRecognizer的代码处添加版本校验,确保仅在符合要求的macOS环境下执行相关逻辑:

#if os(macOS)
@available(macOS 10.14, *)
func detectLanguage(text: String) -> String? {
    let recognizer = NLLanguageRecognizer()
    recognizer.processString(text)
    return recognizer.dominantLanguage?.rawValue
}
#endif

内容的提问来源于stack exchange,提问作者shim

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 19:37:34