Recorded – watch the full episode on YouTube.
Apple's Combine framework was released about nine months ago. In your opinion, what is the main aim of Combine?
Daniel Steinberg: I was not a fan of reactive programming. But now we have Combine and that's going to be our future. What Combine is supposed to solve if you look at what Apple says is Apple says, “we've used delegates here, we've used callbacks, we've used
NotificationCenter, we've used KVO. We've used all sorts of things when we do
URLSession over the years. Let's unify that into one little bag. And we'll call that bag Combine."
“It's a nice way of piping through these APIs and now by SwiftUI instances, just waiting for something to happen.”
And the nice thing is, unlike third party libraries, Apple has wrapped their APIs in that. So I still post a notification the same way, but I can register for notification using Combine and now I can pipe it through the Combine pipeline and the Combine pipeline says, “we've got all these publishers for
NotificationCenter, and KVO and all these things, we're going to unify that with Combine and now we give you these operators to transform them into what your GUI wants." And so you can use map to take a notification, reach inside the user info dictionary and pull out the thing you want and say, "oh, it's JSON; oh Combine has something that takes that JSON and turns it into one of my types."
And so you get this nice pipeline. What does it solve for me? It's a nice way of piping through these APIs and now by SwiftUI instances, just waiting for something to happen. “Oh, look. I've got something new to display.”
“The reason I think that it helps to unify this is you see these things and say, "Oh, I recognize that." That's just this thing that I already know. And instead of using it in the asynchronous world, we've already used it in the synchronous world where we've taken a function and applied it to every element of an array.”
Paul Hudson: Do you think it's necessary to have an understanding of functional programming before using Combine? Or you can say, “Yeah, map,
flatMap(), whatever, I'm going just straight to Combine and I'll just figure it out on the way”?
Daniel Steinberg: You can go straight to Combine. The reason I think that it helps to unify this is you see these things and say, “oh, I recognize that.” That's just this thing that I already know. And instead of using it in the asynchronous world, we've already used it in the synchronous world where we've taken a function and applied it to every element of an array. I don't have to wait for a callback for that.
I'm not waiting for a network call. It's not necessary, but it's nice. You know that moment where you realize, “oh my gosh, all these things are the same.” That's a delightful moment. In math, in science, you learn biology separate from chemistry separate from... And then you get to a point where you say, “oh my gosh. It's just different ways of looking at the same world we live in.” And the same for math, we have algebra and geometry and we have topology and we've got all these things. And you get to a point where you see, we're asking the same questions of all of them.
This transcript was recorded as part of Swiftly Speaking. You can watch the full original episode on YouTube, or subscribe to the audio version on Apple Podcasts.
SPONSORED Build a functional Twitter clone using APIs and SwiftUI with Stream's 7-part tutorial series. In just four days, learn how to create your own Twitter using Stream Chat, Algolia, 100ms, Mux, and RevenueCat.
Sponsor Hacking with Swift and reach the world's largest Swift community!
Link copied to your pasteboard.