Skip to content

Latest commit

 

History

History
53 lines (29 loc) · 1.37 KB

File metadata and controls

53 lines (29 loc) · 1.37 KB

RxSwift

Why using RxSwift

Making serialization of data/event streams and asynchronous tasks more convenient

  • Asynchrony is simplified with declarative programming: no more nested callbacks, delegates, notifications, KVOs
  • Safe multi-threading with .observerOn(scheduler)
  • Clean code and release pressures in controller layers

Subjects

PublishSubject

  • Only accepts events that occur after subscribing to him

ReplySubject

  • Accepts event after subscribing to him, as well as receive the event that was send before him(buffersize: the number of previous events)

BehaviorSubject (the most common usage)

  • Accepts event after subscribing to him, as well as the last event

Variable

  • Wrapped BehaviorSubject
    • Use .asObservable to unbox
  • Modify the value of the object when issuing an event

Transformation

  1. Map
  2. FlatMap
    • FlatMapLatest: only care about changes in the value of the lastest subsription

Resouces Release

  1. Dispose (MRC)
    • Dispose Bags (ARC)

Example: Tableview with RxSwift

RxSwift Example

Related Articles or Resources

Credits from: This article

MVVM & RxSwift