The Combine framework provides a declarative Swift API for processing values over time using publishers, subscribers, and operators (FRP). It introduces the concept of back pressure to prevent overflow and includes built-in support for assigning values and debugging streams. Combine is integrated with SwiftUI and uses the same supported platforms, providing a standardized way to work with asynchronous data in Apple ecosystems.
17. COMBINE IS
A low level framework
Deeply integrated with SwiftUI
Closed source
Not available on Linux
The first Swift FRP library that has back pressure built in
27. SUBSCRIBER
‣ Requests values from a publisher
‣ Acts on values as it receives them
‣ Declares an Input type and a Failure type
28. SUBSCRIBING TO A PUBLISHER
A subscriber can subscribe to a publisher if:
‣ Its input type matches the output type of the publisher
‣ Its failure type matches that of the publisher
Publisher Subscriber
O
F
I
F
29. SUBSCRIBING TO A PUBLISHER
A subscriber can subscribe to a publisher if:
‣ Its input type matches the output type of the publisher
‣ Its failure type matches that of the publisher
31. Assign Subscriber
Assigns elements it receives to an object property at a keypath
The assign(to:on:) operator creates an Assign subscriber
and subscribes it to the upstream publisher
33. OPERATORS
Operate on streams and allow you to:
‣ Transform values
‣ Filter values
‣ Combine publishers together
‣ Manipulate timing
‣ Perform sequence and aggregation operations
35. Many operators subscribe to the upstream publisher
and return a publisher of their own
This allows you to compose them into pipelines
EXAMPLE: CALLING A WEB SERVICE
40. DEBUG OPERATORS
Combine ships with some handy operators that you can
insert into your pipelines to debug them:
‣ print(_:to:)
‣ breakpoint(receiveSubscription:receiveOutput:
receiveCompletion:)
‣ breakpointOnError()
‣ handleEvents(receiveSubscription:receiveOutput:
receiveCompletion:receiveCancel:receiveRequest:)
50. RESOURCES
‣ Using Combine web book (free):
https://heckj.github.io/swiftui-notes/
‣ Combine: Asynchronous Programming with Swift (ebook):
https://store.raywenderlich.com/products/combine-
asynchronous-programming-with-swift
‣ WWDC: Introducing Combine (video)
https://developer.apple.com/videos/play/wwdc2019/722/
‣ WWDC: Combine in Practice (video)
https://developer.apple.com/videos/play/wwdc2019/721/