簡體   English   中英

Swift Package 管理器 - 分發已經存在的 Cocoapod

[英]Swift Package Manager - Distribute an already existing Cocoapod

我想讓我現有的 Cocoapods 也可用作 Swift Package。 事情就是這樣。 我的一個 pod 依賴於另一個,所以我將它添加到我的 Swift package 中:


// swift-tools-version:5.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "Luminous",
    products: [
        // Products define the executables and libraries a package produces, and make them visible to other packages.
        .library(
            name: "Luminous",
            targets: ["Luminous"]),
    ],
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        // .package(url: /* package url */, from: "1.0.0"),
        .package(
            url: "https://github.com/andrealufino/Deviice.git",
            from: "1.30.2"
        )
    ],
    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 this package depends on.
        .target(
            name: "Luminous",
            dependencies: [],
            path: "Sources"),
        .testTarget(
            name: "LuminousTests",
            dependencies: ["Luminous"]),
    ]
)

我的另一個問題是:為什么安裝 package 時包含示例文件夾? 這是圖片。

文件夾結構

此外,最后一件事,當我構建添加了 package 的項目時,它失敗了,因為它找不到依賴項的模塊。 錯誤是No such module Deviice

我想我添加了足夠的細節,如果您需要更多,請詢問。

我會Deviice未找到的設備。 其他問題與本地路徑有關。

您可以看到您的 package (在下一條評論中,“包”可以理解為庫,也可以理解為可執行文件,在“子包”或“真正的可執行文件”的情況下通常用於測試目的。

let package = Package(
    name: "Luminous",  // Name of your package
    products: [],      // What packages people will see relying on internal sub-packages
    dependencies: [],  // External packages you relies on
    targets: []        // Internal "sub-packages", etc.
)

每個target都有一個dependencies: [] ,這是您放置其他目標(“內部”或公共目標的名稱,您之前在dependencies[]中所述)的名稱。

.target(
        name: "Luminous",
        dependencies: [], //Put here names of either sub packages OR public package you "called before"
        path: "Sources")

在你的情況下:

.target(
        name: "Luminous",
        dependencies: ["Deviice"],
        path: "Sources")

確實,您自己寫道:

.testTarget(
            name: "LuminousTests",
            dependencies: ["Luminous"])

所以你說它取決於子Deviice “Luminous”,這里的邏輯與 Device 相同。

您可以使用Alamofire+Image 的 Package作為示例。 它用作外部依賴Alamofire ,並按原樣放置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM