Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to expose your project code to a Xcode playground when using cocoapods?

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:

  • Create a new framework target
  • Add your code to the framework target (with the right access levels)
  • Add a playground file to the workspace
  • Build your framework
  • Then the framework will be available within the playground.

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

like image 504
fespinozacast Avatar asked Dec 01 '17 09:12

fespinozacast


People also ask

How do I run code in Xcode playground?

In the Swift Playgrounds app on your Mac, click Run My Code (or use the Touch Bar). If there are instructions on the right side of the screen, they slide down when you click Run My Code, so you can watch your code run in the live view. When you click Stop, the instructions slide back up.


1 Answers

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'
like image 104
onmyway133 Avatar answered Oct 01 '22 08:10

onmyway133