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
How to use cocoapods with 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 init
with 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。这是一个单一的命令。
- To Install:
gem install cocoapods-playgrounds
- To Use:
pod playgrounds Alamofire
- Wait for playground to open then build it.
- 安装:
gem install cocoapods-playgrounds
- 使用:
pod playgrounds Alamofire
- 等待游乐场打开然后建造它。
回答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 添加一个方案并手动构建它可以像这里讨论的那样工作。
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
- Create project
- Pod init
- Add dependency
- Add playground to your workspace
- Add 'link_with' directive for your playground
- 创建项目
- Pod初始化
- 添加依赖
- 将游乐场添加到您的工作区
- 为您的游乐场添加“link_with”指令
回答by Sergey Kuznetsov
What works for me in Xcode 10 is:
在 Xcode 10 中对我有用的是:
- Create simple Single View App;
- Init it with all pods needed as usual;
- Crate a new separate Playground somewhere on the disc;
- After that just go to your Single View App workspace and use "Add files to.." command in Project Navigator, and add your Playground;
- 创建简单的单视图应用程序;
- 像往常一样用所有需要的 pod 初始化它;
- 在光盘上的某处创建一个新的独立游乐场;
- 之后,只需转到您的 Single View App 工作区并使用 Project Navigator 中的“Add files to..”命令,然后添加您的 Playground;
Now you can use all "Import" directives you needed in your playground.
现在您可以在您的 Playground 中使用您需要的所有“导入”指令。