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