Swift Package Manager with resources compile errors
Asked Answered
P

1

2

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'

or:

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

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

I also tried .copy("Resources/one.xml"), etc

What am I missing?

Penates answered 17/10, 2020 at 14:38 Comment(0)
C
4

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")
Crow answered 17/10, 2020 at 20:48 Comment(5)
Well spotted, thanks. Did it generate the resource_bundle_accessor file for you? I'm still getting the "Type 'Bundle' has no member 'module'" error (referring to your question here).Penates
Please fix errors, push a new version, and ask a new question, mention it here so I can see whats going on.Crow
Thanks - posted new question here: #64408450Penates
Thank you, thank you, thank you! Whoever thought "cannot infer contextual base in reference to member 'target'" is a good English error message for: "you missed a comma" should be …Highlander
Chech this out: -> #65246276Bowens

© 2022 - 2024 — McMap. All rights reserved.