I take back my previous answer.
It is possible to add a Playground to a Swift Package.
Open your Swift Package in Xcode, add an iOS/macOS/tvOS Playground, and add your code to the Playground.
Click on the Playground in the Project navigator, and in the File Inspector, make sure you have "Build Active Scheme" checked, then run your Playground. Everything then "Should Just Work".
You can even change the Playground Platform in File Inspector, stop the Playground and rerun, and it should rebuild your Package and rerun your Playground with the new Platform setting.
It may take Xcode a few seconds to figure out that your Package has been built for the target Platform before the "Module 'PackageName' was created for incompatible target" error goes away.
Post
Replies
Boosts
Views
Activity
Take the current URL to Fruta and go up on https://web.archive.org, then paste in the URL without the "https://" prefix into the box on the form (developer.apple.com/documentation/swiftui/fruta_building_a_feature-rich_app_with_swiftui)
I've had good success going back to December 2020, but feel free to download anything prior to June 2021 and diff the different versions you download
Have you seen/heard of the "Nef" project?
https://github.com/bow-swift/nef
Disclaimer, I have not used this, I found it last night searching for a different Playground problem.
Short answer:
Your Package needs to be part of a Project (or Workspace) for a Playground inside of your Package to be able to find any public structs/classes that your Package provides.
Longer answer:
The Fruta demo that's mentioned in WWDC 10096 has the NutritionFacts Package added to the Fruta Project already. This means that the person who set up the Fruta Project dragged and dropped the NutritionFacts Package into the Fruta Project, causing Xcode to automagically set up a Target for the Package, and the dev then added the Package to all of the existing Targets in the Project (added NutritionFacts Package to "General -> Frameworks and Libraries [and Embedded Content]" for each existing Target).
You can test this yourself by creating a test Package on the command line/in Xcode, then dragging/dropping it from Finder into a test Project; Xcode will quietly and in the background create a new build target for the Package that you just imported, but you'll still need to add the Package by hand to the main Target in your test Project.
To run the NutritionFacts Playground that has been added to the Fruta Project, you will need to build the NutritionFacts Target (select NutritionFacts Target, then hit "Product -> Build" or "⌘-B") before you try to run the NutritionFacts Playground, or you will see errors about "cannot find NutritionFact in scope" when you first try to run the Playground.
A few extra things:
You may already have done this, but for people new to Swift/Packages/Playgrounds, the structs/classes in your Package that you want to use in a Project or Playground need to be marked public. This includes having a default public init() initializer for structs in your Package, because Xcode doesn't create these by default.
The Fruta project currently (July 2021) on Apple's website is for Xcode 13. You'll have to use some kind of mirror (perhaps "web dot archive dot org") to download older copies of the Fruta Project if you're still running Xcode 12. Going back to say November 2020 or so should get you the version of the Fruta Project for Xcode 12.