Combine - result0924/iosLearning GitHub Wiki

How to use Futures and Promises in Combine

  • convert @escaping closures into Publishers.

what-is-the-observableobject-protocol-in-swifts-combine

  • Conforming to the ObservableObject protocol provides a handy way to monitor when one of its @Published properties change.
  • StateObject vs ObservedObject

RunLoop.Main vs DispatchQueue.Main

run loop main 和 dispatch queue main
在combine的scheduler上有那些異同
相同點是都在main thread上執行
不同的地方在於
RunLoop.Main會在用戶交互動作完才更新
ex. 使用者在滾動視圖、會等滾動完才更新UI
但DispatchQueue.Main在滾動的期間就會即時更新

Back-Pressure

Combine extends functional reactive programming by embedding the concept of back-pressure. 
Back-pressure is the idea that the subscriber should control how much information it gets at once and needs to process. 
This leads to efficient operation with the added notion that the volume of data processed through a stream is controllable as well as cancellable.

Subject

  • PassthroughSubject
like doorbell so when you not at home and someone comes and drinks the bell. 
you will not come to know, when you will reach back to the home.
you will not come to know, that someone came and ran the bell
  • CurrentValueSubject
it is like lighting of a bull, so even when you are not at home
if some one comes and turns on the light, you will come to know about it
whenever you will reach back to home.
so state is being retained in case of current value subject

Refer