9

I have an existing projects of a framework and library and would like them to use Swift Package Manager.

I have a Xcode 11 and have already already read Creating a Swift Package with Xcode.

After adding Package.swift to the project and an application target

import PackageDescription

let package = Package(
    name: "MyLibrary",
    platforms: [
        .macOS(.v10_13),
    ],
    products: [
        .library(name: "MyLibrary", targets: ["MyLibrary"]),
    ],
    dependencies: [
        .package(url: "https://url/of/another/package/named/Utility", from: "1.0.0"),
    ],
    targets: [
        .target(name: "MyLibrary", dependencies: ["Utility"]),
        .testTarget(name: "MyLibraryTests", dependencies: ["MyLibrary"]),
    ]
)

I get an error

No such module 'PackageDescription'

How can I import PackageDescription module?

Blazej SLEBODA
  • 8,936
  • 7
  • 53
  • 93
  • 4
    Is your `Package.swift` part of an Xcode Target? It is not a normal file that gets compiled by you but by the build system and it links in `PackageDescription`. The only time I have seen this is when it accidentally gets added into a normal Xcode target. – bscothern Dec 09 '19 at 23:16
  • Yes, the file is a part of the application target – Blazej SLEBODA Dec 10 '19 at 12:05
  • 4
    That is your problem then. You need to have all of the source files that are part of the package products not in an Xcode target. You then need to drag the package into Xcode since it is a local package. You then setup any Xcode targets needing the package to link against it. [This](https://developer.apple.com/videos/play/wwdc2019/408/) WWDC session goes into lots of details about how Xcode and SwiftPM work together. – bscothern Dec 11 '19 at 16:37
  • Hi @Adobels, how did you solve your issue? Best – MGY Jan 13 '20 at 11:51

1 Answers1

-2

I just added line below at the very first line of the Package.swift file and it worked for me.

// swift-tools-version:4.0

Note: Please do not write any thing even comment before this line

After that do not forget to run swift build command

Sultan Ali
  • 2,497
  • 28
  • 25