1
0
mirror of https://github.com/metabolist/metatext synced 2025-01-10 00:54:26 +01:00
metatext-app-ios-iphone-ipad/Shared/Extensions/Publisher+Extensions.swift

20 lines
550 B
Swift
Raw Normal View History

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