33

I just started with swift 3 and made a simple app in xcode using Swift 3.0 . Now i want to add a third party library using Swift Package Manager . I am following installation method given in this link . I created Package.swift file which looks like this

import PackageDescription

let package = Package (
name : "SwiftPM",
dependencies : [
.Package(url: "https://github.com/ArtSabintsev/Siren.git", majorVersion: 1)
])

but i get error No such module "PackageDescription"

Ahsan Attari
  • 987
  • 3
  • 12
  • 26

5 Answers5

19

Refer to the solution in this link:

https://forums.kodeco.com/t/server-error-no-such-module-packagedescription/177438

Command:

sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
Trí Chồn
  • 617
  • 8
  • 15
16

The Swift Package Manager and Xcode are orthogonal. That is, you can't expect to compile Package.swift in Xcode; it simply won't work. Instead, until Xcode supports the package manager, you need to have two distinct builds - one with the package manager and one with Xcode.

So, using the Swift Package Manager, once you've defined Package.swift and formulated your directory structure as expected by the package manger, you perform simply:

swift build

Then for Xcode, you create an Xcode project that uses your source code, but not Package.swift. You'll need to clone the Siren.git project, explicitly - into your Xcode build's source files.

GoZoner
  • 67,920
  • 20
  • 95
  • 145
  • i did tried to import all Siren files explicitly and paste them into my xcode , but that was also not working – Ahsan Attari Sep 30 '16 at 16:32
  • Perhaps the Siren.git project has dependencies itself? If so, for your Xcode build, you'll need to download all the dependencies explicitly and include them in the Xcode build. If not that, you'll need to update your question with more details - showing the errors. – GoZoner Sep 30 '16 at 16:34
  • I recommend using a `git submodule` if you need to clone the dependency into your xcode project. – Richard Apr 24 '17 at 02:50
  • Hi, I created Siren and just came across this post. Please leave an issue on the Siren repo if this is still an issue: https://github.com/ArtSabintsev/Siren/issues – ArtSabintsev Aug 28 '17 at 18:45
14

For me the issue turned out to be Target Membership. I created the Package.swift file manually inside an iOS app project.

Solution:

  • Select and go to the Package.swift file
  • Open the File Inspector on the right side
  • Deselect any modules inside Target Membership section

enter image description here

Jay Mehta
  • 1,511
  • 15
  • 20
12

Swift 3/4

Navigate to your project folder through a terminal and run these commands swift package init --type library first and then swift package generate-xcodeproj

Reference

Pratik
  • 676
  • 10
  • 9
5

For other people who faced the same error as this:

Fix your Package.swift syntax

I got this error because Xcode hadn't parsed Package.swift fully yet, because of syntax errors.

In my case, I had a .target(name: "name-of-target", dependencies: [""]). As soon as I removed the empty dependency string (""), Xcode immediately parsed the file, and the error disappeared. Remember to save the file though.

Also, GoZoner and Pratiks answers are outdated:

  • Xcode has integration with Swift Packages now (as shown above)
  • swift package generate-xcodeproj is deprecated, shown by the error message when using it:

warning: Xcode can open and build Swift Packages directly. 'generate-xcodeproj' is no longer needed and will be deprecated soon.

More information about what that is, and why its gone here.

Ben Butterworth
  • 22,056
  • 10
  • 114
  • 167