2
votes

I am very new to package manager and can't seem to import a library correctly. I am using the following code:

import PackageDescription

let package = Package(
    name: "MyAppName",
    products: [
        .executable(name: "MyAppName", targets: ["MyAppName"])
    ],
    dependencies: [
        .package(url: "https://github.com/socketio/socket.io-client-swift", .upToNextMinor(from: "13.1.0"))
    ],
    targets: [
        .target(name: "MyAppName", dependencies: ["SocketIO"], path: "./Source Files")
    ]
)

After creating this file and placing it in my project main directory, I open a terminal window and type swift build. The files are fetched however I get the following error message:

could not find target(s): MyAppName; use the 'path' property in the Swift 4 manifest to set a custom target path

I really don't understand the products and targets section of the package file and what I am doing wrong. I just put my app "MyAppName" for the executable and target but don't quite understand if that is correct. Also, not sure the path is correct. I want the libraries to be added to a folder titled Source Files in my main project directory.

1

1 Answers

4
votes

Everything in your Package.swift looks fine, you only need to put MyAppName directory with the source files in one of the directories Sources, Source, src, srcs in the top-level directory. So the top-level directory (the one where Package.swift is located) should have the following structure:

TopLevelDirectory |- Package.swift |- Sources |- MyAppName |- MyAppNameSource1.swift |- MyAppNameSource2.swift

Alternatively, you can add the 'path' property to the definition of the target "MyAppName" and to specify where the directory with the sources resides.

Reference: https://github.com/apple/swift-package-manager/blob/master/Documentation/PackageDescriptionV4.md#target-format-reference