`

[IOS]如何使用Swift Package Manager

    博客分类:
  • IOS
阅读更多

视频参考: 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

Screenshot showing a newly created standalone Swift package named ExamplePackage. The Editor area shows the package's manifest file while the Navigator area shows the package's contents and the Utilities area displays the information about the package manifest.

 

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.

 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics