Group Group Group Group Group Group Group Group Group

raywenderlich.com Forums

An Introduction to the Swift Package Manager

In this tutorial you will create an executable package and a library package with the Swift Package Manager.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/750-an-introduction-to-the-swift-package-manager

When I use the swift package init --type executable command I get the following error message:

error: unable to invoke subcommand: /Library/Developer/CommandLineTools/usr/bin/swift-package (No such file or directory)

Using MacOS Sierra v 10.12.3 and Xcode v 8.2.1

I experienced this when I tried the tutorial too. It turned out that my Mac was using the command line tools of an earlier version of Xcode than 8.2.1. Here’s how I ended up fixing it; maybe the same solution will work for you.

Open Xcode, select Xcode > Preferences in the menu, and select the Locations tab. Check that ‘Command Line Tools’ is set to Xcode 8.2.1. Then try the swift package command again.

1 Like

hi,

could you show me how to use this to install https://github.com/remzr7/Surge into a new Xcode project?

Hey!

Since Surge has Swift package Manager Support, you can add

.Package(url: "https://github.com/mattt/Surge/")

to your dependencies.

Note that Surge doesn’t seem to have a stable release with Swift 3 support yet.

Thank you very much for this tutorial. It is promising to get to use Swift outside Xcode. On Ubunto 16.04 I am facing the following problem:

// swift-tools-version:4.0

import PackageDescription

let package = Package(
name: “Flag”,
dependencies: [
.Package(url: “…/Atlas”)
]
)

$ swift build
error: /home/mjeragh/Projects/Flag
manifest parse error(s):
/home/mjeragh/Projects/Flag/Package.swift:8:6: error: type ‘Package.Dependency’ has no member ‘Package’
.Package(url: “…/Atlas”)
^~~~~~~
PackageDescription.Package.Dependency:2:24: note: did you mean ‘package’?
public static func package(url: String, from version: PackageDescription.Version) -> PackageDescription.Package.Dependency
^
PackageDescription.Package.Dependency:3:24: note: did you mean ‘package’?
public static func package(url: String, _ requirement: PackageDescription.Package.Dependency.Requirement) -> PackageDescription.Package.Dependency
^
PackageDescription.Package.Dependency:4:24: note: did you mean ‘package’?
public static func package(url: String, _ range: Range<PackageDescription.Version>) -> PackageDescription.Package.Dependency
^
PackageDescription.Package.Dependency:5:24: note: did you mean ‘package’?
public static func package(url: String, _ range: ClosedRange<PackageDescription.Version>) -> PackageDescription.Package.Dependency
^

Please Help.

I figured it out.
It was the comment
// swift-tools-version:4.0

1 Like

Thank you for this into to Swift PM, it was helpful. Unfortunately, I can’t puzzle out how to use Swift PM in a typical GUI project in Xcode (8.3.2).

Basically, I have an existing project that is a “Cocoa Application”. It uses a framework from a GitHub repo. I’d like to use Swift PM to include that framework in my project but I can’t figure out how to organize that sort of project in Xcode using Swift PM.

I followed this tutorial using swift-tools-version:4.0 Package Manager and had to make a few changes to the ../Flag/Package.swift file:

import PackageDescription

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

Also, if you choose to tag your library with anything less than x.x.x (i.e. x.x), it will not work. Package manager expects the version tag in x.x.x format.

1 Like

This was my issue as well. I removed the commented line and had no further issues. Thanks!

Where is that comment???

what means “non-host platforms’” ?
in “Until the Swift Package Manager supports non-host platforms…”

This tutorial is more than six months old so questions regarding it are no longer supported for the moment. We will update it as soon as possible. Thank you! :]