Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift Package Manager (SPM): Error importing library

Tags:

swift

I'm facing problems while importing a library I created.

This is the Package.swift of my executable:

import PackageDescription

let package = Package(
  name: "PayBackCodingChallenge",
  dependencies: [
    .package(url: "../NumberChecker", from: "1.0.0"),
  ],
  targets: [
    .target(
      name: "PayBackCodingChallenge",
      dependencies: []),
  ]
)

When I try to import NumberChecker in my main.swift I get the following message: No such module 'NumberChecker':

import NumberChecker

let arguments = CommandLine.arguments

if arguments.count != 3 {
  print("USAGE: PayBackCodingChallenge [data] [target]")
  print("  data: File containing list of numbers ")
  print("  target: Target number")
} else {
  let data = arguments[1]
  let target = arguments[2]
  print(data + " " + target)
}

My NumberChecker library is located in a directory at the same level as PayBackCodingChallenge and compiles correctly. What could be the problem?

Thanks in advance!

like image 847
gmoraleda Avatar asked Oct 30 '22 00:10

gmoraleda


1 Answers

You should add NumberChecker as a dependency to PayBackCodingChallenge:

... targets: [ .target( name: "PayBackCodingChallenge", dependencies: ["NumberChecker"]), ] ...

like image 83
Fred Appelman Avatar answered Nov 15 '22 06:11

Fred Appelman