How to use Swift Package Manager in Playgrounds?

I couldn't figure out how to make SPM work with plagrounds in Xcode 11. I think that would be an awesome option to explore third party API and sample out projects. Any help on this?

Replies

+1 Yeah, the same question hee.

It would be great to have an ability either to easily connect playground to project/workspace, or import local and remote swift packages. Really-really desirable feature.

+1

+1

The best way to get your request in front of folks who have the power to change things is to file an enhancement request.

Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

An option is use nef - it is an open source project an let you import third party libraries in your Playgrounds. For now, it is compatible with Cocoapods but we are working on open it for anothers dependency managers like Carthage and SPM.


About SPM is not it an easy task, and it will be a bit different as Apple has prepared Xcode11 but I have good feelings and I think it could be ready for Sept-Oct.


Any help is always welcomed.

In Xcode 12, you can now use Swift Packages with Xcode Playgrounds.

You can find additional details and a sample project in this WWDC20 session: Explore Packages and Projects with Xcode Playgrounds

Ensure to check the new "Build active scheme" checkbox in the inspector for your existing Playgrounds.
I found out that as of Xcode 12.2 SwiftPM do not work reliably with playground. Currently, I can't make it work.

I use 2 slightly different ways to marry a package with playgrounds: by connecting them through a workspace and through a project. It worked once, and to make it work I had to restart Xcode. But since I decided to replace the package, I was unable to make it work ever since.

At this point I'm not sure if I'm doing something wrong or is it an Xcode bug. I've decided to stop trying and give up on playgrounds until SwiftPM support will become dead simple. Too many hours wasted.

Build active scheme is turned on.