gpt4 book ai didi

ios - Swift 包管理器混合语言源文件

转载 作者:可可西里 更新时间:2023-11-01 01:08:35 35 4
gpt4 key购买 nike

出于某种原因,当我尝试在我的 Package.swift 文件上运行 swift build 时:import PackageDescription

let package = Package(
name: "mobile-HDISegurado-ios",
dependencies: [
.package(url: "https://github.com/watson-developer-cloud/swift-sdk", from: "0.30.0"),
],
targets: [
.target(
name: "mobile-HDISegurado-ios",
dependencies: ["WatsonDeveloperCloud"],
path: "mobile-HDISegurado-ios",
exclude: [
"Config",
"Public",
"Resources",
]
)
] )

我遇到了以下错误:

error: target at '.../mobile-HDISegurado-ios' contains mixed language source files; feature not supported

更多详情:

  • swift package tools-version: 4.1.0
  • 运行 Cocoapods 的项目工作区。

最佳答案

SPM 现在支持混合语言源文件,但您可能必须将它们分成多个目标。

来自 the relevant docs :

Targets can contain Swift, Objective-C/C++, or C/C++ code, but an individual target can’t mix Swift with C-family languages. For example, a Swift package can have two targets, one that contains Objective-C, Objective-C++, and C code, and a second one that contains Swift code.

在实践中,您应该将您的 ObjC/C/C++ 文件移动到一个目录,将您的 Swift 文件移动到另一个目录,然后这样修改您的 Package.swift:

products: [
.library(
name: "MyLibrary",
targets: ["MyLibrarySwift", "MyLibraryObjC"]),
],
.target(name: "MyLibraryObjC",
path: "Sources/MyLibraryObjC"
),
.target(name: "MyLibrarySwift",
path: "Sources/MyLibrarySwift"
)

关于ios - Swift 包管理器混合语言源文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51540665/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com