How to use cocoapods with playground?

邮差的信 提交于 2019-11-28 03:57:21
jkistler

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.
Paul Van Wieren

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.

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.

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!