1
0
mirror of https://github.com/metabolist/metatext synced 2024-12-18 20:34:43 +01:00
metatext-app-ios-iphone-ipad/Shared/Extensions/Publisher+Extensions.swift
Justin Mazzocchi 24dd407caa
Refactoring
2020-08-02 00:02:03 -07:00

20 lines
579 B
Swift

// Copyright © 2020 Metabolist. All rights reserved.
import Foundation
import Combine
extension Publisher {
func assignErrorsToAlertItem<Root: AnyObject>(
to keyPath: ReferenceWritableKeyPath<Root, AlertItem?>,
on object: Root) -> AnyPublisher<Output, Never> {
self.catch { [weak object] error -> AnyPublisher<Output, Never> in
DispatchQueue.main.async {
object?[keyPath: keyPath] = AlertItem(error: error)
}
return Empty().eraseToAnyPublisher()
}
.eraseToAnyPublisher()
}
}