为项目中的多个目标和平台使用 Swift 包? [英] Consume Swift Package for multiple targets and platforms in a project?

查看:29
本文介绍了为项目中的多个目标和平台使用 Swift 包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含多个目标的项目,例如一个 iOS 应用、一个 watchOS 应用和一些框架.如何将相同的 Swift 包分配给我的所有目标?Xcode 只让我选择一个:

I have a project with multiple targets, such as an iOS app, a watchOS app, and some frameworks. How can I assign the same Swift Package to all my targets? Xcode only let's me select one:

如果我再次尝试添加 Swift 包,以便尝试将其分配给项目中的另一个目标,则会出现错误:

If I try to add the Swift Package again so I can try assigning it to another target in my project, I get an error:

这样做的正确方法是什么?下面是包清单在 Swift 包中的样子.在这方面有什么事情要做吗,或者我必须在 Xcode 中做一些不同的事情?

What is the correct way to do this? Below is what the package manifest looks like in the Swift Package. Is there something to be done on that side or something I have to do different in Xcode?

import PackageDescription

let package = Package(
    name: "Alamofire",
    platforms: [
        .macOS(.v10_12),
        .iOS(.v10),
        .tvOS(.v10),
        .watchOS(.v3)
    ],
    products: [
        .library(
            name: "Alamofire",
            targets: ["Alamofire"])
    ],
    targets: [
        .target(
            name: "Alamofire",
            path: "Source")
    ],
    swiftLanguageVersions: [.v5]
)

推荐答案

我也遇到了同样的问题,只找到了这两个解决方案:

I had the same problem, and I only found this two solutions:

首先,将包添加到第一个目标:

First, add the package to the first target:

然后,第一个选项是转到另一个目标,General 选项卡,然后在 Frameworks、Libraries 和 Embedded Content 按 +,选择包并按 Add:

Then, the first option is going to the other target, General tab, and in Frameworks, Libraries and Embedded Content press +, select the package and press Add:

另一个选项是构建阶段并在 Link Binary With Libraries 中重复类似的方式:

The other option is going to build Phases and repeat a similar way in Link Binary With Libraries:

目前,我只知道这个选项,我希望将来 Apple 可以通过多检查来改进它,例如.

At the moment, I only know this options, I hope in the future Apple could improve this with a multi-check, for example.

这篇关于为项目中的多个目标和平台使用 Swift 包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆