How to Use Cocoapods with Playground

How to add a CocoaPod framework to Xcode 8 Playground

UPDATE

As of:

Xcode 8.2

You no longer need to add your pod folder into resources, simply use it as you would in the project.

Example:

Playground


Pre Xcode 8.1

Thanks to Eric Aya, I have found a solution based on his first suggestion.

In order to add a CocoPods framework to Playground, follow these steps:

  1. Add pods to your pod file and hit pod install
  2. Add a new Playground file
  3. Click on the Sources folder in your playground
  4. Click on the + for Add Files to Sources
  5. Add you pod folder, in our case HanakeSwift
  6. Import your project pods framework import Pods_PodsPlayground
  7. Build and access your framework!

Step 3

Step 3

Step 4

Step 4

Step 5

Step 5

Step 6, 7

Step 6, 7

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

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'

Using pods with Playgrounds in Xcode 9 (beta)

I upgraded to 9 yesterday and this morning found that I could no longer add playgrounds to my workspace with a right click/New File. The template isn't there.
The solution is to create the new playground. Open in Finder. Drag it onto the workspace. It now belongs to the workspace and has access to the podfile.

How to import RxSwift in Playground of xcode?

  1. You should clone the RxSwift repository on your computer
  2. Open Rx.xcworkspace
  3. Build the RxSwift-macOS scheme
  4. Open Rx.playground in the Rx.xcworkspace tree view and add a new page
  5. import RxSwift in the new page.
  6. Choose View > Debug Area > Show Debug Area

steps 3 and 4

step 5

How to import Swift Package in Playground?

In Xcode 12, you can use Swift Packages with Xcode Playgrounds.

  • Open Xcode
  • Create a new Workspace (File > New > Workspace...)
  • Add the desired Swift package via File > Add Files to "Workspace Name"... selecting the package directory.
  • Create a new Playground via 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 now import the Package target into your Playground and starting exploring the Package's functionality.

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.



Related Topics



Leave a reply



Submit