【问题标题】:How to create an SPM package based on ObjC code?如何基于 ObjC 代码创建 SPM 包?
【发布时间】:2023-02-25 13:26:33
【问题描述】:

我想创建一个基于 Objective-C 代码的 SwiftPackageManager 库,但我似乎无法理解我遗漏了什么。

我对 include 文件夹中的 vanilla ObjC interface .h 文件的最新更改是添加一个额外的 C 标头,其中包含 de ObjC 但仍然没有成功。我错过了什么?

Package.swift 文件是默认生成的文件,根据我的阅读,它应该会自动从 include 文件夹生成模块映射。

我的 swift-tools-version 是 5.5

【问题讨论】:

    标签: swift objective-c xctest swift-package-manager


    【解决方案1】:

    弄清楚了。 我添加了一个指定我的 ObjC 标头的模块映射并且它有效

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

    【讨论】:

    • 不确定你的设置有什么问题,但是如果有人有类似的问题,这里有一个指向文档的链接github.com/apple/swift-package-manager/blob/main/Documentation/…
    • 我有一个类似的问题我不认为我们需要触摸 module.modulemap 因为它更复杂的布局,我的问题是 publicHeaderPath 搜索相对于目标而不是根,你能在问题中分享你的 Package.swift
    【解决方案2】:

    所以只是有同样的问题。 (我的 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" 或根据文档忽略(似乎它是相对于目标而不是根)。我认为我们不应该为如此简单的结构触摸 module.modulemap

    【讨论】:

      猜你喜欢
      • 2015-03-13
      • 2020-05-30
      • 1970-01-01
      • 2023-03-10
      • 1970-01-01
      • 1970-01-01
      • 2022-10-07
      • 1970-01-01
      • 2022-11-08
      相关资源
      最近更新 更多