RxCombine
RxCombine 2.0.1


Rxcombineは、RxSwiftとAppleのCombine Frameworkの間で双方向の型ブリッジングを提供します。
注:これは非常に実験的であり、基本的には迅速に把握されたPOCです。私は喜んでPR、アイデア、意見、または改善を受け入れます。ありがとう ! :)
ExamPlearppフォルダーのサンプルアプリをご覧ください。プロジェクトを開く前に、 pod installを実行します。

次の行をPodfileに追加します。
pod 'RxCombine'次の依存関係をパッケージに追加します。swiftファイル:
. package ( url : " https://github.com/CombineCommunity/RxCombine.git " , from : " 1.6.0 " )カルタゴのサポートは、事前に構築されたバイナリとして提供されます。
Cartfileに次のことを追加します。
github "CombineCommunity/RxCombine"
Rxcombineは、いくつかのヘルパーとコンバージョンを提供して、既存のRXSWIFTタイプを橋渡しして結合するのに役立ちます。
注:rxswiftのcombineで並列演算子の詳細について詳しく知りたい場合は、rxswiftをチェックしてチートシート(またはgithub)を組み合わせてください。
Observable (およびその他のObservableConvertibleType s)にはAnyPublisher<Element, Swift.Error> Observable返すpublisherプロパティがあります。 let observable = Observable . just ( " Hello, Combine! " )
observable
. publisher // AnyPublisher<String, Swift.Error>
. sink ( receiveValue : { value in ... } )RelaysとSubjects 、 toCombine()メソッドを使用してCombine-Counterpartsに変換できます。そのため、通常の組み合わせの被験者であるかのように使用し、既存の被験者に接続することができます。 let relay = BehaviorRelay < Int > ( value : 0 )
// Use `sink` on RxSwift relay
let combineSubject = relay . toCombine ( )
combineSubject . sink ( receiveValue : { value in ... } )
// Use `send(value:)` on RxSwift relay
combineSubject . send ( 1 )
combineSubject . send ( 2 )
combineSubject . send ( 3 )Rxcombineはいくつかのヘルパーとコンバージョンを提供して、コードとタイプを既存のRxSwiftコードベースに埋めるのに役立ちます。
Publisherは、基礎となるPublisherをミラーリングするObservable<Output>を提供するasObservable()メソッドを備えています。 // A publisher publishing numbers from 0 to 100.
let publisher = AnyPublisher < Int , Swift . Error > { subscriber in
( 0 ... 100 ) . forEach { _ = subscriber . receive ( $0 ) }
subscriber . receive ( completion : . finished )
}
publisher
. asObservable ( ) // Observable<Int>
. subscribe ( onNext : { num in ... } )PassthroughSubjectとCurrentValueSubjectどちらもasAnyObserver()メソッドを持ち、 AnyObserver<Output>返します。 RXSWIFTコードからそれにバインドすると、イベントが基礎となる組み合わせの主題にプッシュされます。 // Combine Subject
let subject = PassthroughSubject < Int , Swift . Error > ( )
// A publisher publishing numbers from 0 to 100.
let publisher = AnyPublisher < Int , Swift . Error > { subscriber in
( 0 ... 100 ) . forEach { _ = subscriber . receive ( $0 ) }
subscriber . receive ( completion : . finished )
}
// Convert a Publisher to an Observable and bind it
// back to a Combine Subject ???
publisher . asObservable ( )
. bind ( to : subject )
Observable . of ( 10 , 5 , 7 , 4 , 1 , 6 )
. subscribe ( subject . asAnyObserver ( ) ) もちろん、MIT ;-)ライセンスファイルを参照してください。
AppleのロゴとCombineフレームワークは、Apple Inc.のプロパティです。