Combine 5

How to weak link Combine in macOS 10.14 and iOS 12

Issue #593

#if canImport(Combine) is not enough, need to specify in Other Linker Flags

OTHER_LDFLAGS = -weak_framework Combine

Read more

How to convert from callback to Future Publisher in Combine

Issue #527

import Foundation
import Combine

public typealias TaskCompletion = (Result<(), Error>) -> Void

public protocol Task: AnyObject {
    var name: String { get }
    func run(workflow: Workflow, completion: TaskCompletion)
}

public …

How to use objectWillChange in Combine

Issue #513

A publisher that emits before the object has changed

Use workaround DispatchQueue to wait another run loop to access newValue

.onReceive(store.objectWillChange, perform: {
    DispatchQueue.main.async {
        self.reload()
    }
}) …

How to map error in Combine

Issue #506

When a function expects AnyPublisher<[Book], Error> but in mock, we have Just

func getBooks() -> AnyPublisher<[Book], Error> {
    return Just([
        Book(id: "1", name: "Book 1"),
        Book(id: …

How to flat map publisher of publishers in Combine

Issue #451

For some services, we need to deal with separated APIs for getting ids and getting detail based on id.

To chain requests, we can use flatMap and Sequence, then collect to wait and get all elements in a single publish

FlatMap

Transforms …