ios - 关于多平台库的基本 Swift 包管理器问题

标签 ios swift macos swift-package-manager

我费了好大劲才弄清楚这个问题。我知道如何使用 CocoaPods 执行此操作,但 SPM 似乎变得更好了。 我无法从 the official SPM docs 中得出任何结论 | ,关于这个具体问题。

我正在开发一个 Swift 框架,旨在嵌入到应用程序和应用程序(iOS 和 OSX)中。我在 xcodeproj 中有几个目标,每个平台都有目标。我可以单独运行 xcodebuild,或者使用 CocoaPods 按需生成它们。

我似乎无法让 SPM 做同样的事情。它顽固地只构建 OSX 版本,我看不到任何重定向相同源文件的命令。

使用相同的源文件非常重要,而不是拥有相同文件的两个副本,因此我的所有目标都需要指向相同的目录。

这是 Package.swift 文件现在的样子:

// swift-tools-version:4.2

import PackageDescription

let package = Package(
    name: "WhiteDragon",
    products: [
        .library(
            name: "WhiteDragon",
            targets: ["WhiteDragon"]
        ),
    ],
    targets: [
        .target(
            name: "WhiteDragon",
            dependencies: [],
            path: "WhiteDragon/Classes"
        ),
        .testTarget(
            name: "WhiteDragonTests",
            dependencies: ["WhiteDragon"],
            path: "WhiteDragonTests"
        ),
    ],
    swiftLanguageVersions: [.v4_2]
)

我正在继续挖掘,并尝试各种疯狂的想法,但我还没有。我是 SPM 的新手,我发现几乎每个人都只是在讨论使用它来拉取依赖项,或者他们使用与 init 相同的原始小结构。

我很想使用 RTFM,但到目前为止我有点失望,很高兴被引导到可以给我答案的“M”。

非常感谢!

更新:这是 podspec,它给了我我需要的东西(特里爵士做了一些修改):

Pod::Spec.new do |spec|
    spec.name                       = 'WhiteDragon'
    spec.summary                    = 'A Cocoa Framework that Provides an Application-Level Interaction With a BAOBAB Server.'
    spec.description                = 'The White Dragon Cocoa Framework is a Swift shared framework designed to allow easy development of iOS/MacOS RVP apps. It completely abstracts the connection to BAOBAB Servers, including administration functions.'
    spec.version                    = '1.0.0.1000'
    spec.ios.deployment_target      = '11.0'
    spec.osx.deployment_target      = '10.11'
    spec.homepage                   = '<MILLENIUM HAND AND SHRIMP>'
    spec.social_media_url           = 'https://twitter.com/BUGRIT'
    spec.author                     = { '<MUMBLE, MUMBLE>' }
    spec.documentation_url          = '<BUGRIT>'
    spec.license                    = { :type => 'MIT', :file => 'LICENSE.txt' }
    spec.source                     = { :git => '<GASPODE!>', :tag => spec.version.to_s }
    spec.source_files               = 'WhiteDragon/Classes/**/*'
end

最佳答案

目前 SPM 不支持 iOS 目标。

At this time there is no explicit support for depending on UIKit, AppKit, etc, though importing these modules should work if they are present in the proper system location. We will add explicit support for system dependencies in the future. Note that at this time the Package Manager has no support for iOS, watchOS, or tvOS platforms.

Depending on Apple Modules

关于ios - 关于多平台库的基本 Swift 包管理器问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53135295/

相关文章:

c++ - 访问 mac osx 应用程序包中资源文件夹中的文件

java Scanner 只读取前 2048 个字节

ios - 在 iPad 屏幕上按下 Controller 两次

html - 我怎样才能使位置 :fixed work on iOS 7?

ios - 添加到 Stackview subview 的 CAShapeLayers 仅在一个 subview 上呈现

unit-testing - 在 Swift 中测试断言

ios - 我可以禁用 Mac Catalyst iOS 应用程序上的窗口大小调整功能吗

ios - 如果当前嵌套很深,如何返回根 ViewController?

ios - 如何在不等待 App Review 的情况下继续使用 TestFlight 功能

ios - 在 PHAssetCollection 中过滤矩