RxSwift: ReactiveX for Swift

platforms Carthage compatible QQ Group

(简写: Rx) 是一个可以帮助我们简化异步编程的框架。

它拓展了观察者模式。使你能够自由组合多个异步事件,而不需要去关心线程,同步,线程安全,并发数据以及I/O阻塞。

RxSwift 版本。

它尝试将原有的一些概念移植到 iOS/macOS 平台。

你可以在这里找到跨平台文档 。



18年2月15日

  • 纠正错别字
  • retry 操作符加入演示代码
  • 给 操作符加入演示代码
  • connect 操作符加入演示代码
  • 给 操作符加入演示代码
  • reduce 操作符加入演示代码
  • 给 操作符加入演示代码
  • skip 操作符加入演示代码


Github 搜索…

RxSwift 中文文档 - 图4

定义搜索结果 …

… 然后将结果绑定到 tableview 上

  1. .bind(to: tableView.rx.items(cellIdentifier: "Cell")) {
  2. (index, repository: Repository, cell) in
  3. cell.textLabel?.text = repository.name
  4. cell.detailTextLabel?.text = repository.url
  5. }
  6. .disposed(by: disposeBag)

安装 RxSwift 不需要任何第三方依赖。

打开 Rx.xcworkspace, 选中 RxExample 并且点击运行。 此方法将构建所有内容并运行示例应用程序。

pod --version: 1.3.1 已通过测试

  1. # Podfile
  2. use_frameworks!
  3. target 'YOUR_TARGET_NAME' do
  4. pod 'RxSwift', '~> 4.0'
  5. pod 'RxCocoa', '~> 4.0'
  6. end
  7. # RxTests 和 RxBlocking 将在单元/集成测试中起到重要作用
  8. target 'YOUR_TESTING_TARGET' do
  9. pod 'RxBlocking', '~> 4.0'
  10. pod 'RxTest', '~> 4.0'
  11. end

替换 YOUR_TARGET_NAME 然后在 Podfile 目录下, 终端输入:

carthage version: 已通过测试

添加到 Cartfile

  1. github "ReactiveX/RxSwift" ~> 4.0
  1. $ carthage update

swift build --version: Swift 4.0.0-dev (swiftpm-13126) 已通过测试

创建Package.swift 文件。

  1. $ swift build
  1. $ TEST=1 swift test
  • 添加 RxSwift 作为子模块
  • 前往 Project > Targets > Build Phases > Link Binary With Libraries, 点击 + 并且选中 RxSwift-[Platform]