3

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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
alionthego
  • 8,508
  • 9
  • 52
  • 125

2 Answers2

4

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

Vadim Eisenberg
  • 3,337
  • 1
  • 18
  • 14
  • thanks for you reply. I tried to add a path to my source files, but during the swift build from command line I get the error: 'swift:9:8: error: no such module 'UIKit' import UIKit' as it goes through my source files one by one. not sure what is really happening there and why UIKit is being referenced or why it is going through my source files. I guess my understanding of package manager and dependencies is very limited – alionthego Dec 10 '17 at 07:24
  • You should check where in the source of MyAppName appear references to UIKit. UIKit is a client-side module, it is probably not ported to the server-side. Swift Package Manager is for the server-side code, to run on MacOS and Linux, in a command line. – Vadim Eisenberg Dec 10 '17 at 08:51
  • I should have mentioned previously I am doing this on Xcode for an iOS project, not OS. I wonder if that's the problem – alionthego Dec 11 '17 at 21:25
  • Yes, it could be a problem. See this comment from February 2016 https://stackoverflow.com/questions/34778823/swift-package-manager-uikit-dependency#comment58685107_34779231 – Vadim Eisenberg Dec 12 '17 at 07:23
1

This will be dependencies: inside

  .package(url: "https://github.com/Netvent/storyly-ios.git",
                      .upToNextMajor(from: "1.0.0"))// or `.upToNextMinor

and in target . you have to say .product

.target(name: "segmentify",
            dependencies: [.product(name: "Storyly", package: "storyly-ios")]),
Erhan Demirci
  • 4,173
  • 4
  • 36
  • 44