欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

[IOS]如何使用Swift Package Manager

程序员文章站 2022-05-30 22:25:40
...

视频参考: https://www.youtube.com/watch?v=xu9oeCAS8aA

 

Apple Guide: https://developer.apple.com/documentation/xcode/creating_a_swift_package_with_xcode

 

Swift Package Manager (SwiftPM) 是 Apple 推出的一个包管理工具, 用于创建, 使用 Swift 的库, 以及可执行程序的工具.

 

简要步骤如下:

1. Create a Swift Package

File > New > Swift Package

[IOS]如何使用Swift Package Manager
            
    
    博客分类: IOS Swift Package Manager 

 

2. Configure Your Swift Package

 

// swift-tools-version:5.1
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"]),
    ]
)

 

 

3.  Organize Your Code with Swift Packages

Click the + button in the “Frameworks, Libraries, and Embedded Content” section and select the local package’s library to link it into your app target.