美文网首页
Swift Package

Swift Package

作者: CodingTom | 来源:发表于2021-08-17 20:42 被阅读0次

创建Package.swift

mkdir webDemo
cd webDemo
swift package init

设置版本的语法:

// Depending on a branch (master in this case):
.package(
    url: "https://github.com/johnsundell/files.git",
    .branch("master")
)

// Depending on an exact commit:
.package(
    url: "https://github.com/johnsundell/files.git",
    .revision("0e0c6aca147add5d5750ecb7810837ef4fd10fc2")
)

// Tag
.package(
    url: "https://github.com/johnsundell/files.git",
    .exact("4.0.0")
)

 .package(url: "https://github.com/apple/example-package-playingcard.git", from: "3.0.0"),

// Using 'path', we can depend on a local package that's
// located at a given path relative to our package's folder:
.package(path: "../CalendarKit")

运行项目

swift build

这时候会下载依赖的package,下载完后会编译项目。

完整Demo

// swift-tools-version:5.2
import PackageDescription

let package = Package(
    name: "hello",
    platforms: [
       .macOS(.v10_15)
    ],
    dependencies: [
        // 💧 A server-side Swift web framework.
        .package(url: "https://hub.fastgit.org/liuyujie/vapor.git", .branch("main")),
    ],
    targets: [
        .target(
            name: "App",
            dependencies: [
                .product(name: "Vapor", package: "vapor")
            ],
            swiftSettings: [
                // Enable better optimizations when building in Release configuration. Despite the use of
                // the `.unsafeFlags` construct required by SwiftPM, this flag is recommended for Release
                // builds. See <https://github.com/swift-server/guides/blob/main/docs/building.md#building-for-production> for details.
                .unsafeFlags(["-cross-module-optimization"], .when(configuration: .release))
            ]
        ),
        .target(name: "Run", dependencies: [.target(name: "App")]),
        .testTarget(name: "AppTests", dependencies: [
            .target(name: "App"),
            .product(name: "XCTVapor", package: "vapor"),
        ])
    ]
)

重新生成 xcodeproj文件(仅Mac适用)

swift package generate-xcodeproj

官方文档

https://hub.fastgit.org/apple/swift-package-manager/blob/main/Documentation/PackageDescription.md

相关文章

网友评论

      本文标题:Swift Package

      本文链接:https://www.haomeiwen.com/subject/jknibltx.html