简体   繁体   中英

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

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'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM