RxSwift: ReactiveX for Swift
(简写: Rx) 是一个可以帮助我们简化异步编程的框架。
它拓展了观察者模式。使你能够自由组合多个异步事件,而不需要去关心线程,同步,线程安全,并发数据以及I/O阻塞。
是 Rx 的 Swift 版本。
它尝试将原有的一些概念移植到 iOS/macOS 平台。
你可以在这里找到跨平台文档 。
18年2月15日
- 纠正错别字
- 给 操作符加入演示代码
- 给 replay 操作符加入演示代码
- 给 操作符加入演示代码
- 给 publish 操作符加入演示代码
- 给 操作符加入演示代码
- 给 skipWhile 操作符加入演示代码
给 操作符加入演示代码
Github 搜索…
定义搜索结果 …
… 然后将结果绑定到 tableview 上
.bind(to: tableView.rx.items(cellIdentifier: "Cell")) {
(index, repository: Repository, cell) in
cell.textLabel?.text = repository.name
cell.detailTextLabel?.text = repository.url
}
.disposed(by: disposeBag)
- Xcode 9.0
- Swift 4.0
- Swift 3.x ()
- Swift 2.3 (使用
rxswift-2.0
分支)
安装 RxSwift 不需要任何第三方依赖。
打开 Rx.xcworkspace, 选中 RxExample
并且点击运行。 此方法将构建所有内容并运行示例应用程序。
pod --version
: 1.3.1
已通过测试
# Podfile
use_frameworks!
target 'YOUR_TARGET_NAME' do
pod 'RxSwift', '~> 4.0'
pod 'RxCocoa', '~> 4.0'
end
# RxTests 和 RxBlocking 将在单元/集成测试中起到重要作用
target 'YOUR_TESTING_TARGET' do
pod 'RxBlocking', '~> 4.0'
pod 'RxTest', '~> 4.0'
end
替换 YOUR_TARGET_NAME
然后在 Podfile
目录下, 终端输入:
carthage version
: 已通过测试
添加到 Cartfile
github "ReactiveX/RxSwift" ~> 4.0
$ carthage update
swift build --version
: Swift 4.0.0-dev (swiftpm-13126)
已通过测试
创建Package.swift
文件。
$ swift build
$ TEST=1 swift test
- 添加 RxSwift 作为子模块
- 前往
Project > Targets > Build Phases > Link Binary With Libraries
, 点击+
并且选中RxSwift-[Platform]
和