我正在尝试在 Xcode Playground 中导入 RxSwift,方法如下:
gem install cocoapods-playgrounds
之后
pod playgrounds RxSwift
但是现在还没有发生。怎么做呢?
Rx.xcworkspace
RxSwift-macOS
方案Rx.xcworkspace
树视图中打开Rx.playground
并添加一个新页面RxSwift
。View > Debug Area > Show Debug Area
这非常简单:
swift
和 ios
标签。 - Suryabrew install finestructure/tap/arena
arena https://github.com/ReactiveX/RxSwift
结果:
➡️ 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'
Arena-Playground
,找到你的 Playground(可能名为 MyPlayground),在那里找到代码。第一次使用可能需要点击 Product -> Build 来启动。Xcode 9.1不再支持
$ pod playgrounds RxSwift,RxCocoa
会产生以下错误
Errno::ENOENT - 没有这样的文件或目录@dir_initialize-/Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/File Templates/Source/Playground with Platform Choice.xctemplate
您可以使用Arena创建一个带有第三方SPM库的游乐场:
arena https://github.com/finestructure/Gala
resolving package dependencies
libraries found: Gala
✅ created project in folder 'SPM-Playground'
那也适用于 RxSwift。
@Jason,你需要运行以下命令:
$ gem install cocoapods-playgrounds
$ pod playgrounds RxSwift,RxCocoa
然后它就会工作了。第二个命令将打开一个已经添加了pods的工作区。只需记得先构建目标,然后就可以在新的playground中玩耍了。
太容易了!
在你的项目中创建playground(当然你需要添加RxSwift的依赖)
在Xcode项目导航中,在playground文件下面,你会找到一个名为source的文件夹
在这个文件夹中创建这个swift文件: https://github.com/ReactiveX/RxSwift/blob/master/Rx.playground/Sources/SupportCode.swift
然后就可以享受它了!
// 例子
import RxSwift
playgroundShouldContinueIndefinitely()
example("of") {
let disposeBag = DisposeBag()
Observable.of("", "", "", "")
.subscribe(onNext: { element in
print(element)
})
}