【问题标题】:Swift Package Manager with resources compile errors带有资源的 Swift 包管理器编译错误
【发布时间】:2020-10-17 14:38:55
【问题描述】:

我正在尝试使用我的 Package.swift 文件中的资源:

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

import PackageDescription

let package = Package(
    name: "MyPackage",
    products: [
        .library(
            name: "MyPackage",
            targets: ["MyPackage"])
    ],
     targets: [
        .target(
            name: "MyPackage",
            resources: [
               .process("Resources/one.xml"),
               .process("Resources/two.json"),
               .process("Resources/three.json"),
             ]
        )
        .testTarget(
            name: "MyPackageTests",
            dependencies: ["MyPackage"]
        )
    ]
)

当我在另一个项目中导入和编译包时,我收到很多错误,例如:

Cannot infer contextual base in reference to member 'target'

或:

Reference to member 'process' cannot be resolved without a contextual type

这些文件位于我的包项目中 Sources -> MyPackage -> Resources

我也试过.copy("Resources/one.xml")

我错过了什么?

【问题讨论】:

    标签: swift xcode swift-package-manager


    【解决方案1】:

    您在target 右括号之后错过了,

            .target(
                name: "BioSwift",
                resources: [
                   .process("Resources/unimod.xml"),
                   .process("Resources/aminoacids.json"),
                   .process("Resources/elements.json"),
                   .process("Resources/enzymes.json"),
                   .process("Resources/functionalgroups.json"),
                   .process("Resources/hydropathy.json")
                ]
            ), // Here is the missed `,`
    

    另外,您无需逐个添加文件!相反,您可以添加一个目录:

    .process("Resources")
    

    【讨论】:

    • 很好,谢谢。它是否为您生成了resource_bundle_accessor 文件?我仍然收到“Type 'Bundle' has no member 'module'”错误(参考您的问题here)。
    • 请修复错误,推送新版本,并提出新问题,在此提及,以便我查看发生了什么。
    • 谢谢 - 在此处发布新问题:stackoverflow.com/questions/64407950/…
    • 谢谢谢谢谢谢!谁认为“无法推断成员'目标'的上下文基础”是一个很好的英文错误消息:“你错过了一个逗号”应该是......
    猜你喜欢
    • 1970-01-01
    • 2020-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    相关资源
    最近更新 更多