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

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


I’ve been kicking the wheels on Xcode 12 and its capability to make use of frameworks and packages with playgrounds. Up till now, I’ve solely been capable of import packages which might be both downloaded or developed regionally on my house system. Nonetheless, plenty 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 a neighborhood Forwarding bundle after which use that code. Lengthy story quick: I might.

Right here’s my playground, efficiently working.

The RuntimeImplementation is asserted in a GitHub-hosted bundle known as Swift-Normal-Utility:

What I did to make this work was that I created what I known as a Forwarding Utility, whose sole job is to create a shell bundle that is dependent upon the distant bundle and forwards it to the playground. It seems like this. It’s a single file known as “Forwarding.swift” (no, the identify is by no means 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 Package deal.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, aside from (as I discussed in my different submit about how you can use SwiftPM packages in playground workspaces) that you will have to stop and re-open the primary beta earlier than you’ll be able to import the forwarding.

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

author avatar
roosho Senior Engineer (Technical Services)
I am Rakib Raihan RooSho, Jack of all IT Trades. You got it right. Good for nothing. I try a lot of things and fail more than that. That's how I learn. Whenever I succeed, I note that in my cookbook. Eventually, that became my blog. 
rooshohttps://www.roosho.com
I am Rakib Raihan RooSho, Jack of all IT Trades. You got it right. Good for nothing. I try a lot of things and fail more than that. That's how I learn. Whenever I succeed, I note that in my cookbook. Eventually, that became my blog. 

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here


Latest Articles

author avatar
roosho Senior Engineer (Technical Services)
I am Rakib Raihan RooSho, Jack of all IT Trades. You got it right. Good for nothing. I try a lot of things and fail more than that. That's how I learn. Whenever I succeed, I note that in my cookbook. Eventually, that became my blog.