久々にCombineを触っていて、 @Published
を用いたプロパティの監視を試みていたところ、以下のようにwillSet
的な挙動をしていた。
ドキュメントにも以下のような記載があったので、そのような仕様らしい。
When the property changes, publishing occurs in the property’s
willSet
block, meaning subscribers receive the new value before it’s actually set on the property.
とはいえ `newValue` は取得できているので、以下のように関数をメンバー数でなくパラメタをもとに実装しておけば、常に最新の状態に基づく処理を実行できる。