Type 'Bundle' has no member "module"
Asked Answered
R

0

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?

Remonstrant answered 17/10, 2020 at 8:53 Comment(5)
What version of Xcode are you using?Benevento
Also why is json file in test target? That is not at all what #63237895 says to do and is not what your Package file says.Benevento
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.Remonstrant
You are using a wrong file tree management. Its not sync with the package.swift content.Lindalindahl
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.Archiepiscopal

© 2022 - 2024 — McMap. All rights reserved.