37

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.

Forge
  • 5,854
  • 6
  • 41
  • 58
vinbhai4u
  • 1,289
  • 2
  • 18
  • 33
  • 1
    It is probably easier to just use a small sample project than to mess around with a playground. For most pods you should be able to simply say "pod try *podname*" – Paulw11 Oct 27 '15 at 12:12
  • 1
    @Paulw11 I agree but some easy test can be done in playground, we must not underestimate the power and speed of playgrounds. It really gives an edge when you just want to try something out. – vinbhai4u Oct 27 '15 at 12:15
  • 2
    according to this problem: [link](https://github.com/CocoaPods/swift/issues/3) you have to create a workspace where the pods are installed and then make a new playground file in this workspace.look to 'orta's response in the link. – Finn Fahrenkrug Oct 27 '15 at 12:21
  • Is there some other way like manual addition of pods project into Playground? – vinbhai4u Oct 27 '15 at 12:21
  • 1
    What I do most of the times is just running `pod try` and using the example projects provided with a pod. – Samuel Mellert Jan 11 '16 at 15:57

5 Answers5

53

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.
nburk
  • 20,293
  • 14
  • 73
  • 116
jkistler
  • 756
  • 5
  • 10
  • 1
    @vinbhai4u this should be the accepted answer, this tool works great and saves a lot of time. – Lars Blumberg Sep 28 '16 at 07:26
  • This didn't work for me. Output in my terminal: `[~]$ pod playgrounds SwiftDate The file /Users/emai/SwiftDatePlayground/SwiftDatePlayground/SwiftDate.xcworkspace does not exist.` – bigpotato Nov 26 '16 at 18:05
  • 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](https://github.com/segiddins/ThisCouldBeUsButYouPlaying/issues/43) – jkistler Nov 30 '16 at 16:52
  • 3
    I've tried that but doesn't work I get no such module 'Parse' `pod playgrounds Parse` – Chlebta Feb 09 '17 at 10:32
  • 3
    Worst name for a repo of all time – wfbarksdale Apr 11 '17 at 01:51
  • 26
    Sadly, the project is no longer maintained and does not work with Xcode 9 – timbru31 Oct 03 '17 at 09:53
17

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.

Community
  • 1
  • 1
Paul Van Wieren
  • 965
  • 1
  • 7
  • 11
6

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
Samuel Mellert
  • 659
  • 1
  • 7
  • 12
  • 3
    The solution above is out of date. You now use 'target blocks' to add pods to a playground. http://stackoverflow.com/questions/37280077/error-with-cocoapods-link-with-after-update-to-1-0-0 – AFraser Jan 12 '17 at 21:01
  • The specification of `link_with` in the Podfile is now unsupported, please use target blocks instead. – Nik Kov Apr 02 '17 at 10:47
  • These comments are timely, but don't help solve the problem. – ahalls Dec 04 '17 at 00:52
2

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.

2

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'
sas
  • 5,839
  • 3
  • 26
  • 45