Home IOS Development Importing Net-based SwiftPM packages to your Xcode Playground — Erica Sadun

Importing Net-based SwiftPM packages to your Xcode Playground — Erica Sadun

0
Importing Net-based SwiftPM packages to your Xcode Playground — Erica Sadun

[ad_1]

I’ve been kicking the wheels on Xcode 12 and its capacity to make use of frameworks and packages with playgrounds. Up till now, I’ve solely been in a position to import packages which might be both downloaded or developed regionally on my house system. Nonetheless, lots of the packages I wish to work with are hosted from GitHub.

I made a decision to comply with a hunch and see if I might import my dependency by way of an area Forwarding package deal after which use that code. Lengthy story quick: I might.

Right here’s my playground, efficiently operating.

The RuntimeImplementation is asserted in a GitHub-hosted package deal referred to as Swift-Basic-Utility:

What I did to make this work was that I created what I referred to as a Forwarding Utility, whose sole job is to create a shell package deal that will depend on the distant package deal and forwards it to the playground. It seems like this. It’s a single file referred to as “Forwarding.swift” (no, the title is in no way magic.) in Sources/. I take advantage of @_exported to ahead the import.

/*
 
 Use this to ahead web-based dependencies to Swift Pkg
 
 */

@_exported import GeneralUtility

Its Bundle.swift installs the dependency:

    dependencies: [ .package(url: "https://github.com/erica/Swift-General-Utility", .exact("0.0.4")), ],
    targets: [
        .target(
            name: "ForwardingUtility",
            dependencies: [ .product(name: "GeneralUtility"), ],
            path: "Sources/"
        ),
    ],

And that’s just about all that there’s to it, apart from (as I discussed in my different publish about the right way to use SwiftPM packages in playground workspaces) that you will have to stop and re-open the primary beta earlier than you may import the forwarding.

Let me know something that I tousled. But additionally let me know if this was useful to you!

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here