Reputation: 2494
In blog posts like https://useyourloaf.com/blog/adding-playgrounds-to-xcode-projects/, or the kickstarter source code http://github.com/kickstarter/ios-oss they add playground to xcode projects in order to have documentation + visual tests of the different view controllers and view components in the app.
The typical way they recommend to do it is like:
This works without using cocoapods, but i have found that it's not the case when you do use cocoapods.
After adding a playground to the Xcode workspace, the Pods are available in the playground, but not my custom framework.
I don't understand how cocoapods work to make the pods available in the playground
I don't understand how internally playground decides which frameworks to have available for import, etc.
Does any of you have achieved this? have pointers to do it?
Thanks
Upvotes: 6
Views: 1681
Reputation: 680
In XCode 13.2 this is much easier.
Open your app project, go to File > New > Playground.
In save window go to the dropdown where it says "Add to:", replace "Don't add to any project or workspace" with your project (See below). Hit Create.
Open playground file within app project window
Import any pod/target from your app or use any class within the playground
Hit the Run/Play icon in the Playground, which will build your entire project first, and then run your playground code at the very end.
Upvotes: 0
Reputation: 48095
It is doable. In your Podfile
, you need to declare targets for both your app and your framework, so that CocoaPods can add pods to both. Here is an example. You can check the tutorial Using Playground, demo and Medium post https://medium.com/flawless-app-stories/playground-driven-development-in-swift-cf167489fe7b
platform :ios, '9.0'
use_frameworks!
pod 'Cheers'
target 'UsingPlayground'
target 'AppFramework'
Upvotes: 6