RxSwift: Reactive Programming wi

2018-11-27  本文已影响102人  lanjing

"If you've ever used an asynchronous callback based API, you've probably dealt with handling the response data ad-hoc all across your codebase, and have most likely decided there was no way to unit test it all... But, let me tell you - there is a better way, and it's called Rx!"
— Krunoslav Zaher, creator of RxSwift

这本书保持了raywenderlich系列图书的一贯水准,讲解清晰易懂,示例丰富,可以算是实战手册。我正用从这本书学到的知识来重构App 5.0版本。

书分为六大部分

Getting Started with RxSwift

在第一部分Getting Started with RxSwift里,介绍了Observable和Subjects的基本概念,并在第四章Observables and Subjects in Practice给出一个小Demo帮助理解这两个概念。动手一试,哪怕只是抄一下代码,都会加深对Observable和Subjects这两个概念的理解。
个人理解,正如从面向过程到面向对象,响应式编程也是编程范式和思考方式上的一个改变。

Operators and Best Practices

在第二部分Operators and Best Practices,以概念讲解加Demo演练的方式讲解Observable上的方法,RxSwift称它为Operators。这些操作十分强大,极富表现力,一两行代码就能实现强大的功能。这些操作符按列别可以分为Filtering、Transforming、Combining和Time Based Operators。

iOS Apps with RxCocoa

第三部分 iOS Apps with RxCocoa,介绍了RxCocoa。遵守职责分离的设计原则,RxSwift和RxCocoa虽然在同一个git仓库中,但它们是两个分开的库。RxSwift是对Swift语言级别的扩展,RxCocoa可是视为对Cocoa和Cocoa Touch的UI库级别的扩展。

Intermediate RxSwift/RxCocoa

第四部分 Intermediate RxSwift/RxCocoa,介绍了RxSwift/RxCocoa中进阶的话题,包括错误处理,调度处理,测试和自定义的响应式扩展。我对测试尤其有兴趣,测试驱动开发想实现起来依旧比较困难。除了开发人员的技术能力和意识,开发工具也是一方面。

RxSwift Community Cookbook

第五部分 RxSwift Community Cookbook,介绍了几个主要的RxSwift开源社区提供的工具库,例如对手势、TableView和CollectionView DataSource的扩展。存储Realm的Rx扩展,以及网络扩Alamofire的扩展,这些库都能提升开发效率。

Putting it All Together

第六部分 Putting it All Together,很贴心的给出两个完整的Demo来示范如何使用RxSwift。在此会发现RxSwift和MVVM是最佳拍档。尽管响应式编程(例如RxSwift,ReactiveCocoa等)不是MVVM的必须。但是没有响应式的加持,MVVM能提升设计和效率的空间十分有限。

看书只是一个起点,列读书笔记也颇为干瘪。等5.0过后整理一下实践总结或许更为有趣。

书的完整目录如下:

Table of Contents: Overview Introduction ............................................................. 15
Section I: Getting Started with RxSwift .............. 21
Chapter 1: Hello RxSwift! ................................. 22
Chapter 2: Observables................................... 44
Chapter 3: Subjects ......................................... 67
Chapter 4: Observables and Subjects in Practice …………………………………………………… 82

Section II: Operators and Best Practices.......... 102
Chapter 5: Filtering Operators ....................... 103
Chapter 6: Filtering Operators in Practice...... 121
Chapter 7: Transforming Operators ............... 142
Chapter 8: Transforming Operators in Practice........................................................... 158
Chapter 9: Combining Operators .................. 179
Chapter 10: Combining Operators in Practice........................................................... 199
Chapter 11: Time Based Operators …………… 220

Section III: iOS Apps with RxCocoa ................. 239
Chapter 12: Beginning RxCocoa ………………. 240
Chapter 13: Intermediate RxCocoa ............... 260

Section IV: Intermediate RxSwift/RxCocoa ..... 283
Chapter 14: Error Handling in Practice.......... 284
Chapter 15: Intro To Schedulers.................... 304
Chapter 16: Testing with RxTest .................... 319
Chapter 17: Creating Custom Reactive Extensions……………………………………………… 335

Section V: RxSwift Community Cookbook ....... 351
Chapter 18: Table and Collection Views ....... 352
Chapter 19: Action ......................................... 357
Chapter 20: RxGesture .................................. 362
Chapter 21: RxRealm ..................................... 367
Chapter 22: RxAlamofire................................ 372

Section VI: Putting it All Together .................... 377
Chapter 23: MVVM with RxSwift ................... 378
Chapter 24: Building a Complete RxSwiftApp ................................................................. 401
Conclusion............................................................ 426

236F74D9-6E7E-44FE-8533-0C71F7BC409A.png
上一篇下一篇

猜你喜欢

热点阅读