如何在 xcode 的 Playground 中导入 RxSwift?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42082864/
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 import RxSwift in Playground of xcode?
提问by Istiak Morsalin
I am trying to import rxswift in xcode playground by this:
我正在尝试通过以下方式在 xcode 操场中导入 rxswift:
gem install cocoapods-playgrounds
and after that
在那之后
pod playgrounds RxSwift
But it is not happening. How to do it?
但它并没有发生。怎么做?
回答by XFreire
- You should clone the RxSwift repositoryon your computer
- Open
Rx.xcworkspace
- Build the
RxSwift-macOS
scheme - Open
Rx.playground
in theRx.xcworkspace
tree view and add a new page import RxSwift
in the new page.- Choose
View > Debug Area > Show Debug Area
- 您应该在您的计算机上克隆RxSwift 存储库
- 打开
Rx.xcworkspace
- 构建
RxSwift-macOS
方案 Rx.playground
在Rx.xcworkspace
树视图中打开并添加一个新页面import RxSwift
在新页面中。- 选择
View > Debug Area > Show Debug Area
回答by abdallah shawky
it's super easy:
这非常简单:
- Create a new project, Xcode menu > File > New > Project… (Single
View App)
- Close Xcode
- Initialize pods in the new project (pod init in terminal)
- Edit Podfile, add RxSwift, RxCocoa
- Install pods (pod install in terminal)
- Open RxSwiftProject.xcworkspace created by CocoaPods
- Build and run project using default scheme
- Add a new playground, Xcode menu > File > New > Playground…
- Select Add to: RxSwiftProject , to add it to the RxSwift workspace
- Save it in the workspace folder
- 创建一个新项目,Xcode菜单>文件>新建>项目...(Single View App)
- 关闭 Xcode
- 在新项目中初始化 pods(终端中的 pod init)
- 编辑 Podfile,添加 RxSwift、RxCocoa
- 安装 pods(在终端中安装 pod)
- 打开 CocoaPods 创建的 RxSwiftProject.xcworkspace
- 使用默认方案构建和运行项目
- 添加一个新的playground,Xcode menu > File > New > Playground…
- 选择 Add to: RxSwiftProject ,将其添加到 RxSwift 工作区
- 将其保存在工作区文件夹中
回答by user6902806
No longer works in Xcode 9.1
不再适用于 Xcode 9.1
$ pod playgrounds RxSwift,RxCocoa
$ pod playgrounds RxSwift,RxCocoa
gives
给
Errno::ENOENT - No such file or directory @ dir_initialize - /Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/File Templates/Source/Playground with Platform Choice.xctemplate
Errno::ENOENT - No such file or directory @ dir_initialize - /Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/File Templates/Source/Playground with Platform Choice.xctemplate
回答by Bartosz Olszanowski
@Jason, you need to run following commands:
@Jason,您需要运行以下命令:
$ gem install cocoapods-playgrounds
$ gem install cocoapods-playgrounds
$ pod playgrounds RxSwift,RxCocoa
$ pod playgrounds RxSwift,RxCocoa
and it'll work. The second command opens a workspace with already added pods. Just remember to first build a target and then you can play with your new playground.
它会起作用。第二个命令打开一个已经添加了 pod 的工作区。请记住首先建立一个目标,然后你就可以在你的新操场上玩耍了。
回答by sas
回答by Mete
As @sas has hinted at, you can use Arena.
正如@sas 所暗示的那样,您可以使用Arena。
To be more specific:
更具体:
One line to install Arena:
一行安装 Arena:
brew install finestructure/tap/arena
One line to create your RxSwift enabled Playground:
一行代码来创建启用 RxSwift 的 Playground:
arena https://github.com/ReactiveX/RxSwift
Results:
结果:
?? Package: https://github.com/ReactiveX/RxSwift @ from(5.1.1)
Resolving package dependencies ...
Libraries found: RxSwift, RxCocoa, RxRelay, RxBlocking, RxTest
Building package dependencies ...
? Created project in folder 'Arena-Playground'
Done! Open Arena-Playground
and find your Playground (probably called MyPlayground), code there. It may require a click on Product -> Build to get going the first time.
完毕!打开Arena-Playground
并找到您的 Playground(可能称为 MyPlayground),在那里编写代码。第一次可能需要单击“产品”->“构建”。
回答by JunYao Yuan
That so easy!
就这么简单!
Create playground in your project(of course you need to need to add the dependency of RxSwift)
In Xcode project navigation, below the playground file, you will find a folder named source
Create this swift file in this folder: https://github.com/ReactiveX/RxSwift/blob/master/Rx.playground/Sources/SupportCode.swift
Then enjoy it!
// example import RxSwift playgroundShouldContinueIndefinitely() example("of") { let disposeBag = DisposeBag() Observable.of("", "", "", "") .subscribe(onNext: { element in print(element) }) }
在你的项目中创建 playground(当然你需要添加 RxSwift 的依赖)
在 Xcode 项目导航中,在 playground 文件下方,您会找到一个名为 source 的文件夹
在此文件夹中创建此 swift 文件:https: //github.com/ReactiveX/RxSwift/blob/master/Rx.playground/Sources/SupportCode.swift
那就尽情享受吧!
// example import RxSwift playgroundShouldContinueIndefinitely() example("of") { let disposeBag = DisposeBag() Observable.of("", "", "", "") .subscribe(onNext: { element in print(element) }) }