How to use cocoapods with playground?

17,717

Solution 1

This is an old question but shows up at the top of Google.

This Could Be Us But You Playing is a command line tool that creates a new Xcode playground with an integrated cocoapod. It also supports integrating multiple cocoapods at once. It's a single command.

  1. To Install: gem install cocoapods-playgrounds
  2. To Use: pod playgrounds Alamofire
  3. Wait for playground to open then build it.

Solution 2

For those using the pre-release 1.0 version of CocoaPods, the 'link_with' directive that @samuel used is deprecated. I tried simply adding my playground as a target in my Podfile, but CocoaPods doesn't recognize it as a valid target.

I found that adding a scheme for the pod I need to use and building it manually works as discussed here.

Manage Schemes enter image description here

To demonstrate this in action, I have created a sample project with Alamofire integrated into a Playground here.

I also came across this library. I haven't had a chance to use it yet, but it looks promising.

Aside: if you'd like to make asynchronous requests in a Playground (e.g. with Alamofire), you'll need to enable indefinite execution as described here.

I hope this helps.

Solution 3

There is an issue of "Little bites of cocoa" explaining how to do this: https://littlebitesofcocoa.com/138-using-cocoapods-in-xcode-playgrounds

  1. Create project
  2. Pod init
  3. Add dependency
  4. Add playground to your workspace
  5. Add 'link_with' directive for your playground

Solution 4

What works for me in Xcode 10 is:

  1. Create simple Single View App;
  2. Init it with all pods needed as usual;
  3. Crate a new separate Playground somewhere on the disc;
  4. After that just go to your Single View App workspace and use "Add files to.." command in Project Navigator, and add your Playground;

Now you can use all "Import" directives you needed in your playground.

Solution 5

If your pods also support the Swift Package Manager, you could try Arena:

arena https://github.com/finestructure/Gala
🔧  resolving package dependencies
📔  libraries found: Gala
✅  created project in folder 'SPM-Playground'
Share:
17,717
vinbhai4u
Author by

vinbhai4u

Crazy for mobile development When I am free you can find me under a book or watching TV Series

Updated on June 03, 2022

Comments

  • vinbhai4u
    vinbhai4u almost 2 years

    I am trying out some pods before I implement it with my main project I want to make sure it works properly for my requirement. Easiest way is to try it with playground.

    I tried pod init with playground which doesn't work

    [!] No xcode project found, please specify one

    Help is much appreciated.

  • Lars Blumberg
    Lars Blumberg over 7 years
    @vinbhai4u this should be the accepted answer, this tool works great and saves a lot of time.
  • bigpotato
    bigpotato over 7 years
    This didn't work for me. Output in my terminal: [~]$ pod playgrounds SwiftDate The file /Users/emai/SwiftDatePlayground/SwiftDatePlayground/SwiftDat‌​e.xcworkspace does not exist.
  • jkistler
    jkistler over 7 years
    I am not sure what happen. I just tested it with SwiftDate and everything worked fine. It looks like other people are having the same issue. See here
  • AFraser
    AFraser over 7 years
    The solution above is out of date. You now use 'target blocks' to add pods to a playground. stackoverflow.com/questions/37280077/…
  • Chlebta
    Chlebta over 7 years
    I've tried that but doesn't work I get no such module 'Parse' pod playgrounds Parse
  • Nike Kov
    Nike Kov about 7 years
    The specification of link_with in the Podfile is now unsupported, please use target blocks instead.
  • Nike Kov
    Nike Kov about 7 years
    Outdated answer
  • wfbarksdale
    wfbarksdale about 7 years
    Worst name for a repo of all time
  • timbru31
    timbru31 over 6 years
    Sadly, the project is no longer maintained and does not work with Xcode 9
  • Just a coder
    Just a coder over 6 years
    outdated? nah man. It just workded for me with Xcode 9 using his steps here -> github.com/paulvanwieren/Pods-In-Playgrounds
  • ahalls
    ahalls over 6 years
    These comments are timely, but don't help solve the problem.
  • Amy L.
    Amy L. over 5 years
    It worked for me with Xcode 9 using the steps provided on GitHub