2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

RxSwift 2.0.0-rc.0 にアップデートしたときの Variable is deprecated ワーニングに対処する

Last updated at Posted at 2016-01-01

おととい RxSwift の 2.0.0 RC がリリースされたので さっそくアップデートしてみました。
ところが たくさんのビルドワーニングが出てしまったので その対処をまとめます。

追記(2016-01-02)

さきほど 2.0.0 がリリースされました。
2.0.0 では Variable から ObservableType の実装自体が取り除かれており、同プロトコル由来のメソッドを使うとビルドエラーになります。

Removes deprecated APIs.
https://github.com/ReactiveX/RxSwift/commit/aca3b2821339654f936dabf7b201f112e0e8a780#diff-0e55b16927fa1b61df214216489f0599L19

ビルドワーニング詳細

ワーニングの内容としては VariableObservableType でなくなるというものです:

'Variable' is deprecated: Variable will remain in the 2.0.0 API, but just use variable.asObservable() because it won't be ObservableType (no way to warn about deprecated interface implementation). Just do, variable.asObservable().map { _ in ...} and ignore this warning.

CHANGELOG にも記載がありました:

Deprecates Variable implementing ObservableType in favor of asObservable().
https://github.com/ReactiveX/RxSwift/blob/83bac6db0cd4f7dd3e706afc6747bd5797ea16ff/CHANGELOG.md#deprecated

対処方法

対処方法としては Variableオブジェクト をいちど asObservable メソッドで Observable に変換したのち ObservableType のメソッドを使います。

注意点として、ObservableVariable と異なり .Completed を出力します:

Now variable also sends .Completed to observable sequence returned from asObservable when deallocated.
https://github.com/ReactiveX/RxSwift/blob/83bac6db0cd4f7dd3e706afc6747bd5797ea16ff/CHANGELOG.md#deprecated

参考資料

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?