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