However, a more awesome example of the power of Combine is in the Subscribers.
For example, see how we can dynamically assign the title field of this Article reference type:That is some really awesome functionality!Inter-op between RxSwift & CombineOf course, the two Reactive frameworks can also live together.
No need to convert you full codebase to Combine: if you want to put an Observable in a SwiftUI, that is possible.
This is how you could convert from Observable to Publisher:The otherway-round should be possible too.
Note that the demand property is unused.
RxSwift has no back-pressure, so when converting, you need to ensure that you only use Observables that you have already throttled and/or you know that wont overrun the UI system.
It would also be possible to create some sort of dynamic operator that does the back-pressure by either dropping or buffering (these are the options in RxJava).
Wrap upAfter a quick dive into this new framework, I'm already thrilled with the potential.
Interestingly Combine does not depend on Foundation types, in fact, it lies at a lower level than Foundation.
Talking with Apple Engineers, it really sounds like they have optimized the hell out of this framework.
Quoting an Apple engineer: “The memory models of RxSwift and Combine are very different.
Combine is really made for performance.
” Looking at the existing Publishers, Apple is already using this in high performance systems, like the RealityKit framework (see for example Scene.
Compared to RxSwift, Combine has very different semantics.
The lack of DisposeBags & the presence of back-pressure are probably the direct effects of Apple doubling down on performance & integrating Combine at other low-level visualization & AR systems.
It is striking that the first FRP framework (by Conal Elliot) was made for visualizations, and used a frame-rate dependent system: with back-pressure, the RP system actually becomes more of a long-polling/sampling system than a full reactive framework like Rx.
In this first beta release, the set of Publishers and Sinks delivered by Apple is still small, but a little bird told us that upcoming releases will have even more convenient Publishers for common observable stuff like URLSession, NotificationCenter & KVO.
I'm exited about using SwiftUI with this Combine framework, and hope you are too!Referenceshttps://developer.
com/posts/the-power-of-key-paths-in-swiftCheck out our other WWDC19 blog posts on https://medium.