swift 如何基于ObjC代码创建SPM包?

dtcbnfnu  于 2023-02-28  发布在  Swift
关注(0)|答案(2)|浏览(156)

我想创建一个基于Objective-C代码的SwiftPackageManager库,但我似乎不能领会我错过了什么。
我对include文件夹中的普通ObjC interface .h文件的最新修改是添加了一个额外的C头文件,其中包含了de ObjC,但仍然没有成功。

Swift文件是默认生成的文件,根据我所读到的,它应该会自动从include文件夹生成模块Map。
我的swift-tools版本是5.5

q8l4jmvw

q8l4jmvw1#

我想明白了。我添加了一个模块Map来指定我的ObjC头,它工作了

不确定这是否是正确的方法,因为include文件夹应该已经自动执行此操作。

i7uaboj4

i7uaboj42#

所以刚刚有同样的问题。(我的5美分)这是5月Package.swift

// swift-tools-version: 5.7
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "AlgorithmSDK",
    platforms: [
        .iOS(.v13)
    ],
    products: [
        // Products define the executables and libraries a package produces, and make them visible to other packages. , "AlgorithmSDKObjc"
        .library(
            name: "AlgorithmSDK",
            targets: ["AlgorithmSDK","AlgorithmSDKObjc" ]),
    ],
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        // .package(url: /* package url */, from: "1.0.0"),
    ],
    targets: [
        // Targets are the basic building blocks of a package. A target can define a module or a test suite.
        // Targets can depend on other targets in this package, and on products in packages this package depends on.
        .target(
            name: "AlgorithmSDK",
            dependencies: []),
        
        .testTarget(
            name: "AlgorithmSDKTests",
            dependencies: ["AlgorithmSDK"]),
        
        .target(
            name: "AlgorithmSDKObjc",
            dependencies: [],
            publicHeadersPath:"include"),//<----- This path is relative to the target! (and can be ignored)
        
    ]
)

其结构为:

根据文档,publicHeadersPath应该是publicHeadersPath:"include" OR忽略(看起来它是相对于目标而不是根的)。我不认为我们应该为这样一个简单的结构触及module.modulemap

相关问题