Skip to content

Instantly share code, notes, and snippets.

@sahara-ooga
Last active August 19, 2020 07:39
Show Gist options
  • Save sahara-ooga/cfd6dd321f6acd1852d904e38716ab3b to your computer and use it in GitHub Desktop.
Save sahara-ooga/cfd6dd321f6acd1852d904e38716ab3b to your computer and use it in GitHub Desktop.
Combine

Publisher

How to make a Publisher

@Publisher

Subscriber

Lifecycle

receive(subscription:) Exactly One Subscription

receive(_:): zero or more Values will be send

receive(completion:): At most one Completion. once this method is called, then the subscription will end.

Make a subscription

Kind of Subscriber

name descrption
Keypath connect to a specific property
sink Closure
Subject subscribe and multicasts values
Passthrough subject and

Sink

  • .sinkメソッドは単にSinkオブジェクトを生成するだけでなく、そのオブジェクトをAnyCancellable型に型消去する。

assign

Assigns each element from a Publisher to a property on an object.

Reverse lookup

Receive on Main Thread

receive(on:)

Cancel

Subscriber のcancelメソッドが呼び出されると、パイプラインを下流から上流にオペレーターのcancelメソッドが呼び出されていき、Publisherはイベントの発行を停止する。

また、Subscriberの参照を削除することでもcancelメソッドは自動的に呼び出される。

Reference

https://www.apeth.com/UnderstandingCombine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment