带有资源编译错误的 Swift 包管理器 [英] Swift Package Manager with resources compile errors

查看:57
本文介绍了带有资源编译错误的 Swift 包管理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to use resources inside my Package.swift file:

// 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"]
        )
    ]
)

当我在另一个项目中导入并编译该包时,出现很多错误,例如:

When I import and compile the package in another project, I am getting lots of errors, such as:

Cannot infer contextual base in reference to member 'target'

或:

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

文件位于 Sources 中的我的包项目中 ->我的包裹 ->资源

The files are located in my package project in Sources -> MyPackage -> Resources

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

我错过了什么?

推荐答案

你错过了 ,target 右括号后:

You missed a , after the target close parentheses:

        .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 `,`

另外,你不需要一一添加文件!相反,您可以添加一个目录:

Also, you don't need to add files one by one! Instead, you can add a directory:

.process("Resources")

这篇关于带有资源编译错误的 Swift 包管理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆