3

In a vapor project, my folder structure is the following:

Package.swift
Sources/
    -App/
    -Module1/
        -File1.swift
        -File2.swift
        -File3.swift
    -Module2/
        -File4.swift
        -File5.swift
        -File6.swift

After adding the 2 modules in each one of them, I edited the package.swift file to be the following:

let package = Package(
    name: "myapp",
    targets: [
        Target(name: "App", dependencies: ["Module1", "Module2"])
    ],
    dependencies: [
        // Some external dependencies
    ],
    exclude: [
        // Excludes
    ]
)

Importing the 2 local modules works fine, yet when I try to use any functions / objects contained within them I get an "unresolved identifier error"

Anything I am missing?

1 Answer 1

3

You also need to declare Module1 and Module2 as targets.

targets: [
    Target(name: "App", dependencies: ["Module1", "Module2"]),
    Target(name: "Module1"),
    Target(name: "Module2")
],
3
  • 2
    And remember to expose any functions you want to use outside the module as "public" Apr 26, 2017 at 20:54
  • 1
    @Makaronodentro you should edit that into the answer (and also mention open)
    – mmmmmm
    May 6, 2017 at 17:54
  • 1
    @Makaronodentro @Mark You actaully don't need to prefix your methods with open or public if you just prefix your import with @testable instead✌️
    – Sentry.co
    Sep 30, 2017 at 13:45

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.