Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
411 views
in Technique[技术] by (71.8m points)

xcode11 - Consume Swift Package for multiple targets and platforms in a project?

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:

SPM1

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:

SPM2

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]
)
question from:https://stackoverflow.com/questions/57625952/consume-swift-package-for-multiple-targets-and-platforms-in-a-project

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

First, add the package to the first target:

Add package

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:

Adding package in General tab

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

Build Phases

Select package

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

Just Browsing Browsing

2.1m questions

2.1m answers

60 comments

56.9k users

...