Giter Club home page Giter Club logo

rxcombine's Introduction

RxCombine



Build Status Code Coverage for RxCombine on codecov
RxCombine supports CocoaPods RxCombine supports Swift Package Manager (SPM) RxCombine supports Carthage

RxCombine provides bi-directional type bridging between RxSwift and Apple's Combine framework.

Note: This is highly experimental, and basically just a quickly-put-together PoC. I gladly accept PRs, ideas, opinions, or improvements. Thank you ! :)

Basic Examples

Check out the Example App in the ExampleApp folder. Run pod install before opening the project.

Installation

CocoaPods

Add the following line to your Podfile:

pod 'RxCombine'

Swift Package Manager

Add the following dependency to your Package.swift file:

.package(url: "https://github.com/CombineCommunity/RxCombine.git", from: "1.6.0")

Carthage

Carthage support is offered as a prebuilt binary.

Add the following to your Cartfile:

github "CombineCommunity/RxCombine"

I want to ...

Use RxSwift in my Combine code

RxCombine provides several helpers and conversions to help you bridge your existing RxSwift types to Combine.

Note: If you want to learn more about the parallel operators in Combine from RxSwift, check out my RxSwift to Combine Cheat Sheet (or on GitHub).

  • Observable (and other ObservableConvertibleTypes) have a publisher property which returns a AnyPublisher<Element, Swift.Error> mirroring the underlying Observable.
let observable = Observable.just("Hello, Combine!")

observable
    .publisher // AnyPublisher<String, Swift.Error>
    .sink(receiveValue: { value in ... })
  • Relays and Subjects can be converted to their Combine-counterparts using the toCombine() method, so you can use them as if they are regular Combine Subjects, and have them connected to your existing subjects.
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)

Use Combine in my RxSwift code

RxCombine provides several helpers and conversions to help you bridge Combine code and types into your existing RxSwift codebase.

  • Publishers have a asObservable() method, providing an Observable<Output> mirroring the underlying 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 and CurrentValueSubject both have a asAnyObserver() method which returns a AnyObserver<Output>. Binding to it from your RxSwift code pushes the events to the underlying Combine Subject.
// 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())

Future ideas

  • Add CI / Tests
  • Carthage Support
  • Bridge SwiftUI with RxCocoa/RxSwift
  • Partial Backpressure support, perhaps?
  • ... your ideas? :)

License

MIT, of course ;-) See the LICENSE file.

The Apple logo and the Combine framework are property of Apple Inc.

rxcombine's People

Contributors

epatey avatar freak4pc avatar fredyshox avatar lucianopalmeida avatar masters3d avatar schlossm avatar ttozzi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rxcombine's Issues

Build errors v2.0.0 on XCode 12.5 Beta

Hi, you are missing some @available iOS >13 in the latest release. I see you already have these changes in main, any chance of a new release including that? :)

CFBundleVersion is missing

After trying to upload to App Store Connect I got an error: The Info.plist is file is missing the required key: CFBundleVersion

Version 1.2 is not up to date

Many thanks for the last merge on master. But it is not tagged as a new version, so actual version 1.2 it's a old version unusable actually :(

Can you create a version 1.3 with actual master version ?

Many thanks

replaceError(with:) results in EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)

The following code results in a crash when run, but operates fine if you remove the call to replaceError. This is an issue if you want to use the results of an Observable with a Subscriber who's failure is Never.

    let observable = Observable.just("Hello Combine")
            .publisher
            .replaceError(with: "Error")
            .sink(receiveValue: { (value) in
                print(value)
            })

Here is the code that the crash is occurring on (stack frame 2 is the last frame with symbols). Merely calling 'frame variable' from the debugger prompt crashes the debug session inside of Xcode. The automatic variables are as follows:

event RxSwift.Event<τ_0_0.Input>
self τ_0_0
element τ_0_0.Input

extension Subscriber where Failure == Never {
    /// Push a provided RxSwift.event onto the Combine Subscriber.
    ///
    /// - parameter event: RxSwift Event to push onto the Combine Subscriber.
    func pushRxEvent(_ event: RxSwift.Event<Input>) {
        switch event {
        case .next(let element):
            _ = receive(element)
        case .error:
            fatalError("Failure is not an option")
        case .completed:
            receive(completion: .finished)
        }
    }
}

extension Subscriber where Failure == Swift.Error {
    /// Push a provided RxSwift.event onto the Combine Subscriber.
    ///
    /// - parameter event: RxSwift Event to push onto the Combine Subscriber.
    func pushRxEvent(_ event: RxSwift.Event<Input>) {
        switch event {
        case .next(let element):
            _ = receive(element)   <----- Crashes here: Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
        case .error(let error):
            receive(completion: .failure(error))
        case .completed:
            receive(completion: .finished)
        }
    }
}

Here is the full call stack upon crash.

Thread 1 Queue : com.apple.main-thread (serial)
#0	0x00007fff233b167a in Publishers.ReplaceError.Inner.receive(_:) ()
#1	0x00007fff233b1b70 in protocol witness for Subscriber.receive(_:) in conformance Publishers.ReplaceError<A>.Inner<A1> ()
#2	0x000000010802cae6 in Subscriber<>.pushRxEvent(_:) at /Users/doig/Documents/Projects/SwiftUITest/Pods/RxCombine/Sources/Rx+Combine/Subscriber+Rx.swift:35
#3	0x000000010802a5e4 in partial apply for Subscriber<>.pushRxEvent(_:) ()
#4	0x00000001081d83fc in closure #1 in ObservableType.subscribe(_:) at /Users/doig/Documents/Projects/SwiftUITest/Pods/RxSwift/RxSwift/ObservableType+Extensions.swift:23
#5	0x000000010810920f in AnonymousObserver.onCore(_:) at /Users/doig/Documents/Projects/SwiftUITest/Pods/RxSwift/RxSwift/Observers/AnonymousObserver.swift:22
#6	0x00000001081e0ea1 in ObserverBase.on(_:) at /Users/doig/Documents/Projects/SwiftUITest/Pods/RxSwift/RxSwift/Observers/ObserverBase.swift:16
#7	0x00000001081e1155 in protocol witness for ObserverType.on(_:) in conformance ObserverBase<A> ()
#8	0x00000001081b57d9 in Just.subscribe<A>(_:) at /Users/doig/Documents/Projects/SwiftUITest/Pods/RxSwift/RxSwift/Observables/Just.swift:83
#9	0x00000001081d833d in ObservableType.subscribe(_:) at /Users/doig/Documents/Projects/SwiftUITest/Pods/RxSwift/RxSwift/ObservableType+Extensions.swift:25
#10	0x000000010802a171 in RxPublisher.receive<A>(subscriber:) at /Users/doig/Documents/Projects/SwiftUITest/Pods/RxCombine/Sources/Rx+Combine/Observable+Combine.swift:43
#11	0x000000010802a455 in protocol witness for Publisher.receive<A>(subscriber:) in conformance RxPublisher<A> ()
#12	0x00007fff233c1571 in PublisherBox.receive<A>(subscriber:) ()
#13	0x00007fff233c1715 in AnyPublisher.receive<A>(subscriber:) ()
#14	0x00007fff2335eb59 in Publisher.subscribe<A>(_:) ()
#15	0x00007fff233b1023 in Publishers.ReplaceError.receive<A>(subscriber:) ()
#16	0x00007fff2335eb59 in Publisher.subscribe<A>(_:) ()
#17	0x00007fff2333709d in Publisher<>.sink(receiveValue:) ()
#18	0x0000000107114619 in ContentView.init() at /Users/doig/Documents/Projects/SwiftUITest/SwiftUITest/ContentView.swift:63
#19	0x00000001071112c2 in SceneDelegate.scene(_:willConnectTo:options:) at /Users/doig/Documents/Projects/SwiftUITest/SwiftUITest/SceneDelegate.swift:23
#20	0x00000001071116f6 in @objc SceneDelegate.scene(_:willConnectTo:options:) ()
#21	0x00007fff4761d3e0 in +[UIScene _sceneForFBSScene:create:withSession:connectionOptions:] ()
#22	0x00007fff4808f170 in -[UIApplication _connectUISceneFromFBSScene:transitionContext:] ()
#23	0x00007fff4808f4b2 in -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] ()
#24	0x00007fff47bfa7f5 in -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] ()
#25	0x00007fff365d6165 in -[FBSSceneImpl _callOutQueue_agent_didCreateWithTransitionContext:completion:] ()
#26	0x00007fff365fc4d8 in __86-[FBSWorkspaceScenesClient sceneID:createWithParameters:transitionContext:completion:]_block_invoke.154 ()
#27	0x00007fff365e0c45 in -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] ()
#28	0x00007fff365fc169 in __86-[FBSWorkspaceScenesClient sceneID:createWithParameters:transitionContext:completion:]_block_invoke ()
#29	0x0000000108888d48 in _dispatch_client_callout ()
#30	0x000000010888bcb9 in _dispatch_block_invoke_direct ()
#31	0x00007fff3662237e in __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ ()
#32	0x00007fff3662206c in -[FBSSerialQueue _queue_performNextIfPossible] ()
#33	0x00007fff3662257b in -[FBSSerialQueue _performNextFromRunLoopSource] ()
#34	0x00007fff23bd4471 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ ()
#35	0x00007fff23bd439c in __CFRunLoopDoSource0 ()
#36	0x00007fff23bd3bcc in __CFRunLoopDoSources0 ()
#37	0x00007fff23bce87f in __CFRunLoopRun ()
#38	0x00007fff23bce066 in CFRunLoopRunSpecific ()
#39	0x00007fff384c0bb0 in GSEventRunModal ()
#40	0x00007fff48092d4d in UIApplicationMain ()
#41	0x00000001071108ab in main at /Users/doig/Documents/Projects/SwiftUITest/SwiftUITest/AppDelegate.swift:12
#42	0x00007fff5227ec25 in start ()
#43	0x00007fff5227ec25 in start ()

Deprecated?

hey, @freak4pc!
Is this repo deprecated?
it's been more than a year since the last update, new pull requests have been created (and even approved), but nothing merged.

Production Readiness

If you're just using this RxCombine downstream of RxSwift and using both in the same app,

how close is this to production-level? Can I use this for a sophisticated app? Or is it known to break. I'm not worried about feature parity. I'm worried about durability with the operators we have in here today.

Thanks.

watchOS deployment target too low

From Podspec:
s.watchos.deployment_target = '3.0'

However, Combine was introduced in watchOS 6, so in a standalone watchOS app, the library fails to compile.

New replaceError(with:) bug

A second issue showed up with replaceError(with:) in a more complicated piece of code.

extension ObservableConvertibleType {

    /// Returns a `AnyPublisher` of the underlying Observable's Element type
    /// so the Observable pushes events to the Publisher.
    ///
    /// - returns: AnyPublisher of the underlying Observable's Element type.
    /// - note: This is a work around for a crash when using replaceError(with:)
    public func asPublisherReplaceError(with: Element) -> AnyPublisher<Self.Element, Never> {
        return self  // NOTE: This crashes
            .publisher
            .replaceError(with: with)
            .eraseToAnyPublisher()
//        return self  // NOTE: This works
//            .publisher
//            .catch({ _ -> AnyPublisher<Self.Element, Never> in
//                Just(with).eraseToAnyPublisher()
//            })
//            .eraseToAnyPublisher()
    }
}

class Bound<Value>: ObservableObject {
    let bag = DisposeBag()

    var value: Value {
        didSet {
            didChange.send(value)
        }
    }

    let didChange = PassthroughSubject<Value, Never>()

    init(_ value: Value) { self.value = value }
}

extension Observable {
    func asBindableObject(initialValue: Element) -> Bound<Element> {
        let bound = Bound(initialValue)
        subscribe(onNext: { [weak bound] in bound?.value = $0 }).disposed(by: bound.bag)
        return bound
    }
}

class PublishedBehaviorRelay<T> {
    typealias PublishType = AnyPublisher<T, Never>
    typealias BindableType = Bound<T>
    
    let dataSource: BehaviorRelay<T>
    var bindable: BindableType {
        return dataSource
            .asObservable()
            .asBindableObject(initialValue: dataSource.value)
    }
    var publisher: PublishType {
        return dataSource
            .asPublisherReplaceError(with: dataSource.value)
    }
    
    init(initialValue: T) {
        dataSource = BehaviorRelay(value: initialValue)
    }
}

class UserViewModel: ObservableObject {
    @Published var sliderValue = 0.0
    @Published var rxswift = "Boo Hiss"
    
    var sliderString: String {
        return "\(sliderValue)"
    }
}

struct ContentView: View {

    @ObservedObject private var userViewModel: UserViewModel
    
    let relay = PublishedBehaviorRelay(initialValue: "Start")
    
    var cancelables: Set<AnyCancellable> = []
    let disposeBag = DisposeBag()
    
    init() {
        let uvm = UserViewModel()
        userViewModel = uvm
        
        // A publisher publishing numbers
        let data = 0...1000
        data
            .publisher
            .map({ "\($0)" })
            .modulated(0.01, bufferSize: data.count, scheduler: RunLoop.main)
            .eraseToAnyPublisher()
            .asObservable()
            .bind(to: relay.dataSource)
            .disposed(by: disposeBag
        )
        
        // CRASH ON THIS LINE OF CODE
        relay.publisher.assign(to: \.rxswift, on: uvm).store(in: &cancelables) 
        
    }

    var body: some View {
        VStack {
            Slider(value: $userViewModel.sliderValue)
                .padding(.horizontal, 40.0)
            VStack {
                Text("Hello, SwiftUI!")
                    .font(.largeTitle)
                    .foregroundColor(.green)
                    .padding(0.0)
                Text(userViewModel.sliderString)
                    .font(.title)
                    .foregroundColor(Color.black)
                    .multilineTextAlignment(.center)
                Text(userViewModel.rxswift)
            }
        }
    }

}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

This code works fine with the commented out asPublisherReplaceError(with:) but crashes in a different spot than it did before version 1.5 with the current implementation of asPublisherReplaceError(with:).

(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
    frame #0: 0x00007fff233b167a Combine`Combine.Publishers.ReplaceError.(Inner in _50EC2DA41500D4F648F58C2EE8939789).receive(A.Output) -> Combine.Subscribers.Demand + 314
    frame #1: 0x00007fff233b1b70 Combine`protocol witness for Combine.Subscriber.receive(A.Input) -> Combine.Subscribers.Demand in conformance Combine.Publishers.ReplaceError<A>.(Inner in _50EC2DA41500D4F648F58C2EE8939789)<A1> : Combine.Subscriber in Combine + 16
    frame #2: 0x0000000103ba2ae6 RxCombine`Subscriber<>.pushRxEvent(event=RxSwift.Event<τ_0_0.Input> @ scalar, self=<no summary available>) at Subscriber+Rx.swift:35:17
    frame #3: 0x0000000103ba05e4 RxCombine`partial apply for Subscriber<>.pushRxEvent(_:) at <compiler-generated>:0
    frame #4: 0x0000000103ca83fc RxSwift`closure #1 in ObservableType.subscribe(e=, on=0x0000000103ba05b0 RxCombine`partial apply forwarder for (extension in RxCombine):Combine.Subscriber< where A.Failure == Swift.Error>.pushRxEvent(RxSwift.Event<A.Input>) -> () at <compiler-generated>) at ObservableType+Extensions.swift:23:17
    frame #5: 0x0000000103bd920f RxSwift`AnonymousObserver.onCore(event=, self=0x0000600001b8b570) at AnonymousObserver.swift:22:21
    frame #6: 0x0000000103cb0ea1 RxSwift`ObserverBase.on(event=, self=0x0000600001b8b570) at ObserverBase.swift:16:22
    frame #7: 0x0000000103cb1155 RxSwift`protocol witness for ObserverType.on(_:) in conformance ObserverBase<A> at <compiler-generated>:0
    frame #8: 0x0000000103bec049 RxSwift`BehaviorSubject._synchronized_subscribe<Element>(observer=0x0000600001b8b570, self=0x00006000027a8120) at BehaviorSubject.swift:128:18
    frame #9: 0x0000000103beba1c RxSwift`BehaviorSubject.subscribe<Element>(observer=0x0000600001b8b570, self=0x00006000027a8120) at BehaviorSubject.swift:111:33
    frame #10: 0x0000000103ca833d RxSwift`ObservableType.subscribe(on=0x0000000103ba05b0 RxCombine`partial apply forwarder for (extension in RxCombine):Combine.Subscriber< where A.Failure == Swift.Error>.pushRxEvent(RxSwift.Event<A.Input>) -> () at <compiler-generated>, self=0x00006000027a8120) at ObservableType+Extensions.swift:25:40
    frame #11: 0x0000000103ba0171 RxCombine`RxPublisher.receive<Upstream>(subscriber=<no summary available>, self=0x0000600001590e20) at Observable+Combine.swift:43:58
    frame #12: 0x0000000103ba0455 RxCombine`protocol witness for Publisher.receive<A>(subscriber:) in conformance RxPublisher<A> at <compiler-generated>:0
    frame #13: 0x00007fff233c1571 Combine`Combine.PublisherBox.receive<A where A1: Combine.Subscriber, A.Failure == A1.Failure, A.Output == A1.Input>(subscriber: A1) -> () + 33
    frame #14: 0x00007fff233c1715 Combine`Combine.AnyPublisher.receive<A where A == A1.Input, B == A1.Failure, A1: Combine.Subscriber>(subscriber: A1) -> () + 53
    frame #15: 0x00007fff2335eb59 Combine`(extension in Combine):Combine.Publisher.subscribe<A where A1: Combine.Subscriber, A.Failure == A1.Failure, A.Output == A1.Input>(A1) -> () + 873
    frame #16: 0x00007fff233b1023 Combine`Combine.Publishers.ReplaceError.receive<A where A1: Combine.Subscriber, A.Output == A1.Input, A1.Failure == Swift.Never>(subscriber: A1) -> () + 371
    frame #17: 0x00007fff233c1571 Combine`Combine.PublisherBox.receive<A where A1: Combine.Subscriber, A.Failure == A1.Failure, A.Output == A1.Input>(subscriber: A1) -> () + 33
    frame #18: 0x00007fff233c1715 Combine`Combine.AnyPublisher.receive<A where A == A1.Input, B == A1.Failure, A1: Combine.Subscriber>(subscriber: A1) -> () + 53
    frame #19: 0x00007fff2335eb59 Combine`(extension in Combine):Combine.Publisher.subscribe<A where A1: Combine.Subscriber, A.Failure == A1.Failure, A.Output == A1.Input>(A1) -> () + 873
    frame #20: 0x00007fff2339d539 Combine`(extension in Combine):Combine.Publisher< where A.Failure == Swift.Never>.assign<A>(to: Swift.ReferenceWritableKeyPath<A1, A.Output>, on: A1) -> Combine.AnyCancellable + 265
  * frame #21: 0x00000001035e8a22 SwiftUITest`ContentView.init() at ContentView.swift:62:25
    frame #22: 0x00000001035d9847 SwiftUITest`SceneDelegate.scene(scene=0x00007fa1f0705940, session=0x0000600000083e00, connectionOptions=0x00006000015ad6c0, self=0x00006000015ad700) at SceneDelegate.swift:23:27
    frame #23: 0x00000001035d9d36 SwiftUITest`@objc SceneDelegate.scene(_:willConnectTo:options:) at <compiler-generated>:0
    frame #24: 0x00007fff4761d3e0 UIKitCore`+[UIScene _sceneForFBSScene:create:withSession:connectionOptions:] + 1304
    frame #25: 0x00007fff4808f170 UIKitCore`-[UIApplication _connectUISceneFromFBSScene:transitionContext:] + 1018
    frame #26: 0x00007fff4808f4b2 UIKitCore`-[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 304
    frame #27: 0x00007fff47bfa7f5 UIKitCore`-[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 361
    frame #28: 0x00007fff365d6165 FrontBoardServices`-[FBSSceneImpl _callOutQueue_agent_didCreateWithTransitionContext:completion:] + 442
    frame #29: 0x00007fff365fc4d8 FrontBoardServices`__86-[FBSWorkspaceScenesClient sceneID:createWithParameters:transitionContext:completion:]_block_invoke.154 + 102
    frame #30: 0x00007fff365e0c45 FrontBoardServices`-[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 220
    frame #31: 0x00007fff365fc169 FrontBoardServices`__86-[FBSWorkspaceScenesClient sceneID:createWithParameters:transitionContext:completion:]_block_invoke + 355
    frame #32: 0x000000010400ad48 libdispatch.dylib`_dispatch_client_callout + 8
    frame #33: 0x000000010400dcb9 libdispatch.dylib`_dispatch_block_invoke_direct + 300
    frame #34: 0x00007fff3662237e FrontBoardServices`__FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 30
    frame #35: 0x00007fff3662206c FrontBoardServices`-[FBSSerialQueue _queue_performNextIfPossible] + 441
    frame #36: 0x00007fff3662257b FrontBoardServices`-[FBSSerialQueue _performNextFromRunLoopSource] + 22
    frame #37: 0x00007fff23bd4471 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    frame #38: 0x00007fff23bd439c CoreFoundation`__CFRunLoopDoSource0 + 76
    frame #39: 0x00007fff23bd3bcc CoreFoundation`__CFRunLoopDoSources0 + 268
    frame #40: 0x00007fff23bce87f CoreFoundation`__CFRunLoopRun + 1263
    frame #41: 0x00007fff23bce066 CoreFoundation`CFRunLoopRunSpecific + 438
    frame #42: 0x00007fff384c0bb0 GraphicsServices`GSEventRunModal + 65
    frame #43: 0x00007fff48092d4d UIKitCore`UIApplicationMain + 1621
    frame #44: 0x00000001035d8e2b SwiftUITest`main at AppDelegate.swift:15:7
    frame #45: 0x00007fff5227ec25 libdyld.dylib`start + 1
    frame #46: 0x00007fff5227ec25 libdyld.dylib`start + 1
(lldb) 

Stack frame 4 is this code

    public func subscribe(_ on: @escaping (Event<Element>) -> Void)
        -> Disposable {
            let observer = AnonymousObserver { e in
                on(e)   <----- CRASH HERE
            }
            return self.asObservable().subscribe(observer)
    }

Xcode 12.5 Compilation Issue

Xcode 12.5 fails to compile the framework if the framework's target < 13.0. Looks like the Subject+Rx.swift file is missing some @available attributes. I've opened a PR with the fix here: #22

Unable to use in a CocoaPod

We tried to use RxCombine in a pod that we're developing. Our pod requires iOS 14.0, however, when deploying the pod via pod repo push, it can't pass CocoaPods validation due to RxCombine's deployment target being set to iOS 9.0:

    - ERROR | xcodebuild:  RxCombine/Sources/Combine+Rx/Subject+Rx.swift:19:49: error: 'Subject' is only available in iOS 13.0 or newer
    - NOTE  | xcodebuild:  RxCombine/Sources/Combine+Rx/Subject+Rx.swift:19:17: note: add @available attribute to enclosing protocol

Is such a low deployment target necessary? Correct me if I'm wrong, but there's no sense using RxCombine before iOS 13 anyway?

Bridging RxSwift to SwiftUI

Haven't really been able to test this out as I've been fighting with Xcode 11 and just some general bugginess but here's a first stab at this:

class Bound<Value>: BindableObject {
    let bag = DisposeBag()

    var value: Value {
        didSet {
            didChange.send(value)
        }
    }
    
    let didChange = PassthroughSubject<Value, Never>()
    
    init(_ value: Value) { self.value = value }
}

extension Observable {
    func asBindableObject(initialValue: Element) -> Bound<Element> {
        let bound = Bound(initialValue)
        subscribe(onNext: { [weak bound] in bound?.value = $0 }).disposed(by: bound.bag)
        return bound
    }
}

Thoughts?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.