xcode 如何在 Playground 中使用 cocoapods?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33367609/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 08:07:24  来源:igfitidea点击:

How to use cocoapods with playground?

iosxcodeswiftcocoapodsswift-playground

提问by vinbhai4u

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.

在我用我的主要项目实现它之前,我正在尝试一些 pods 我想确保它可以正常工作满足我的要求。最简单的方法是在操场上尝试。

I tried pod initwith playground which doesn't work

我试过pod init在操场上不起作用

[!] No xcode project found, please specify one

[!] 没有找到xcode项目,请指定一个

Help is much appreciated.

非常感谢帮助。

回答by jkistler

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

这是一个老问题,但出现在谷歌的顶部。

This Could Be Us But You Playingis 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.

This could be Us But You Playing是一个命令行工具,它创建了一个带有集成 cocoapod 的新 Xcode 游乐场。它还支持一次集成多个 cocoapods。这是一个单一的命令。

  1. To Install: gem install cocoapods-playgrounds
  2. To Use: pod playgrounds Alamofire
  3. Wait for playground to open then build it.
  1. 安装: gem install cocoapods-playgrounds
  2. 使用: pod playgrounds Alamofire
  3. 等待游乐场打开然后建造它。

回答by 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.

对于那些使用 CocoaPods 1.0 预发布版本的用户,@samuel 使用的“link_with”指令已被弃用。我尝试简单地将我的游乐场添加为我的 Podfile 中的目标,但 CocoaPods 无法将其识别为有效目标。

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

我发现为我需要使用的 pod 添加一个方案并手动构建它可以像这里讨论的那样工作。

Manage Schemesenter image description here

管理方案在此处输入图片说明

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

为了在行动证明这一点,我已经创建了一个Alamofire示例项目集成到一个游乐场这里

I also came across thislibrary. 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.

旁白:如果您想在 Playground 中发出异步请求(例如使用 Alamofire),您需要启用此处所述的无限期执行。

I hope this helps.

我希望这有帮助。

回答by Samuel Mellert

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

有一个“小口可可”的问题解释了如何做到这一点: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
  1. 创建项目
  2. Pod初始化
  3. 添加依赖
  4. 将游乐场添加到您的工作区
  5. 为您的游乐场添加“link_with”指令

回答by Sergey Kuznetsov

What works for me in Xcode 10 is:

在 Xcode 10 中对我有用的是:

  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;
  1. 创建简单的单视图应用程序;
  2. 像往常一样用所有需要的 pod 初始化它;
  3. 在光盘上的某处创建一个新的独立游乐场;
  4. 之后,只需转到您的 Single View App 工作区并使用 Project Navigator 中的“Add files to..”命令,然后添加您的 Playground;

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

现在您可以在您的 Playground 中使用您需要的所有“导入”指令。

回答by sas

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

如果您的 pod 也支持 Swift Package Manager,您可以尝试Arena

arena https://github.com/finestructure/Gala
  resolving package dependencies
  libraries found: Gala
?  created project in folder 'SPM-Playground'