1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Server Side SwiftAdvent Calendar 2017

Day 2

Swift4でのPackage.swiftエラー #love_swift

Last updated at Posted at 2018-01-20

Swift愛好会合宿 2018/1/20-1/21で記事書いてます。 #love_swift

Manual Quickstartを参考にVaporでWebサーバー立ててた時の内容です。

$ swift build

をしたときにエラーになりました。

$ swift build
error: manifest parse error(s):
/home/n0bisuke/myswift/webapp/Package.swift:11:10: error: type 'Package.Dependency' has no member 'Package'
        .Package(url: "https://github.com/vapor/vapor.git", majorVersion: 2)
        ~^
$ swift build
error: manifest parse error(s):
/home/n0bisuke/myswift/webapp/Package.swift:10:10: error: ambiguous reference to member 'package'
        .package(url: "https://github.com/vapor/vapor.git", majorVersion: 2),
         ^      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/n0bisuke/myswift/webapp/Package.swift:10:10: note: overloads for 'package' exist with these partially matching parameter lists: (url: String, from: Version), (url: String, Package.Dependency.Requirement), (url: String, Range<Version>), (url: String, ClosedRange<Version>), (url: String, version: Version), (url: String, branch: String), (url: String, revision: String), (url: String, range: Range<Version>)
        .package(url: "https://github.com/vapor/vapor.git", majorVersion: 2),
         ^

他も見てるとSwift3系までのPackage.Swiftでの例が多いので注意が必要そうです。

3系と4系のPackage.swift

  • 3系
// swift-tools-version:3.1

import PackageDescription

let package = Package(
    name: "Hello",
    dependencies: [
        .Package(url: "https://github.com/vapor/vapor.git", majorVersion: 2)
    ]
)
  • 4系
// swift-tools-version:4.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "webapp",
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        .package(url: "https://github.com/vapor/vapor.git", from: "2.4.0"),
    ],
    targets: [
        // Targets are the basic building blocks of a package. A target can define a module or a test suite.
        // Targets can depend on other targets in this package, and on products in packages which this package depends on.
        .target(
            name: "webapp",
            dependencies: ["Vapor"]),
    ]
)

ざっくりと、.Package.packageに、 majorVersionfromに変更するところです。

Swift Package Manager Manifest API Redesignなど参考にすると良さそうです。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?