6

I have tried solutions in this question: Generating resource_bundle_accessor, Type 'Bundle' has no member 'module' however it still does not work.

I am trying to access a simple JSON file in my unit tests. Here is my 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: "MyLibrary",
    platforms: [.iOS("11.0"), .macOS(SupportedPlatform.MacOSVersion.v10_12)],
    products: [
        .library(name: "MyLibrary", targets: ["MyLibrary"])], 
    dependencies: [],
    targets: [
        .target(name: "MyLibrary", dependencies: []),
        .testTarget(
            name: "MyLibraryTests",
            resources: [
                .process("recommendations.json"
            ],
            dependencies: ["MyLibrary"]
        ),
    ]
)
  • I am using swift-tools 5.3
  • I have added the recommendations.json to my package.swift.

I have closed and re-opened Xcode 5 times, yet still it does not create the Bundle.module extension. Here is my file structure:

enter image description here

How can I access my JSON file in my unit tests?

General Failure
  • 2,421
  • 4
  • 23
  • 49
jjjjjjjj
  • 4,203
  • 11
  • 53
  • 72
  • What version of Xcode are you using? – matt Oct 17 '20 at 09:57
  • Also why is json file in test target? That is not at all what https://stackoverflow.com/questions/63237395/generating-resource-bundle-accessor-type-bundle-has-no-member-module says to do and is not what your Package file says. – matt Oct 17 '20 at 10:02
  • Using Xcode 12. Previously I also tried: targets: [ .target(name: "MyLibrary", resources: [.process("recommendations.json"], dependencies: []), .testTarget(name: "MyLibraryTests", dependencies: ["MyLibrary"]), ] JSON file is in test target because that is where I want to use it. I have also tried putting it in the main target, and even tried putting it in both. No combinations work though. – jjjjjjjj Oct 17 '20 at 10:50
  • You are using a wrong file tree management. Its not sync with the package.swift content. – Mojtaba Hosseini Oct 17 '20 at 22:36
  • 1
    I think you need to change `resources: [.process("recommendations.json"]` into `[resources: [.copy("recommendations.json"]]` and keep the file under the test target if this is where is should be. – raistlin Oct 17 '20 at 23:19

0 Answers0