RxCombine
RxCombine 2.0.1


RXCombine은 RXSwift와 Apple의 Combine 프레임 워크 간의 양방향 유형 브리징을 제공합니다.
참고 : 이것은 매우 실험적이며 기본적으로 빠른 POC 일뿐입니다. 기꺼이 PR, 아이디어, 의견 또는 개선을 받아들입니다. 감사합니다 ! :)
examplepp 폴더에서 예제 앱을 확인하십시오. 프로젝트를 열기 전에 pod install 실행하십시오.

podfile 에 다음 줄을 추가하십시오.
pod 'RxCombine'패키지 에 다음 종속성을 추가하십시오. 스위프트 파일 :
. package ( url : " https://github.com/CombineCommunity/RxCombine.git " , from : " 1.6.0 " )Carthage Support는 사전 제작 된 이진으로 제공됩니다.
카트 파일 에 다음을 추가하십시오.
github "CombineCommunity/RxCombine"
RXCombine은 기존 RXSwift 유형을 결합 할 수 있도록 여러 도우미와 전환을 제공합니다.
참고 : RXSwift에서 Combine의 병렬 연산자에 대해 자세히 알아 보려면 RXSwift를 확인하여 치트 시트 (또는 GitHub) 를 결합하십시오.
Observable (및 기타 ObservableConvertibleType s)에는 기본 Observable 미러링하는 AnyPublisher<Element, Swift.Error> 를 반환하는 publisher 속성이 있습니다. let observable = Observable . just ( " Hello, Combine! " )
observable
. publisher // AnyPublisher<String, Swift.Error>
. sink ( receiveValue : { value in ... } )Relays 및 Subjects toCombine() 메소드를 사용하여 Combine-CounterPart로 변환 할 수 있으므로 규칙적인 결합 피험자 인 것처럼 사용할 수 있으며 기존 주제에 연결할 수 있습니다. 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 S는 asObservable() 메소드를 가지고있어 Observable<Output> 기본 Publisher 미러링합니다. // 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 Framework는 Apple Inc의 속성입니다.