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?

koen
  • 5,383
  • 7
  • 50
  • 89

1 Answers1

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")
Mojtaba Hosseini
  • 95,414
  • 31
  • 268
  • 278
  • 1
    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](https://stackoverflow.com/questions/63237395/generating-resource-bundle-accessor-type-bundle-has-no-member-module)). – koen Oct 17 '20 at 22:00
  • Please fix errors, push a new version, and ask a new question, mention it here so I can see whats going on. – Mojtaba Hosseini Oct 17 '20 at 22:12
  • Thanks - posted new question here: https://stackoverflow.com/questions/64407950/swift-package-manager-type-bundle-has-no-member-module-error – koen Oct 17 '20 at 22:26
  • 2
    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 … – axello Oct 25 '20 at 13:15
  • Chech this out: -> https://stackoverflow.com/questions/65245776/swift-package-resource-colors-coming-back-as-nil-in-ci-test-cases-but-return-fi/66803074#66803074 – Ignelio Mar 25 '21 at 15:51