Combine extends the Sequence
protocol to provide a way to create a publisher from a sequence. The publisher
property on a sequence creates a publisher that emits the elements of the sequence, and then finishes.
Here’s an example of how to create a publisher from an array:
import Combine
let array = [1, 2, 3, 4, 5]
array.publisher
.sink {
print($0)
} receiveValue: {
print($0)
}
This code creates a publisher from an array of integers and prints each element to the console.
1
2
3
4
5
finished