Reputation: 6018
Can i import Swift Package to my Playground that is in my workspace? I've already read the answer, but i think it's outdated, because now we can use Swift Packages in iOS projects.
Upvotes: 27
Views: 15860
Reputation: 529
Xcode 14.2
import Package
in PlaygroundIf Xcode still do not see package then:
File > Packages > Resolve Package Versions
Upvotes: 3
Reputation: 7542
Check out Arena, it allows you to create playgrounds with SPM dependencies embedded ready for use.
All it takes is
brew install finestructure/tap/arena
arena alamofire/alamofire
Update: The Swift Package Index has since gained Arena integration and you can create a playground for a package by clicking the "Try in a Playground" button on a package page.
Upvotes: 17
Reputation: 10538
I couldn't get @wolfrevo's answer working. However, I have a solution inspired by his:
File > New > Project
)Muliplatform > App
> NextFile > Swift Packages > Add Package Dependency
)Playground
> NextUpvotes: 2
Reputation: 2032
In Xcode 12, you can use Swift Packages with Xcode Playgrounds.
File > New > Workspace...
)File > Add Files to "Workspace Name"...
selecting the package directory.File > New > Playground...
. Ensure that you select the Workspace we just created as the "Add to" and "Group" option during Playground creation (in the assistant where you select the Playground's location on disk).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.
Upvotes: 29
Reputation: 1436
Still now, Playground does not support the Swift Package Manager. When we try to add the Swift PM from Xcode using
File > Swift Packages > Add Package Dependency
the option is disabled.
An option is to use nef - it is an open-source project an lets you import third-party libraries in your Playgrounds. For now, it is compatible with Cocoapods but nef are working on open it for other dependency managers like Carthage and SPM.
About SPM is not 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.
Upvotes: 7