import Foundation import Combine @available(iOS 14.0, *) extension Publisher { func sinkDispatchTo(_ store: StateStoreViewModel) where SA == Output, Failure == Never { return self .subscribe(on: DispatchQueue.main) .sink { [weak store] (output) in guard let store = store else { return } store.dispatch(action: output) } .store(in: &store.cancellables) } func dispatchTo(_ store: StateStoreViewModel) -> Publishers.HandleEvents> where SA == Output, Failure == Never { return self .subscribe(on: DispatchQueue.main) .handleEvents(receiveOutput: { [weak store] action in guard let store = store else { return } store.dispatch(action: action) }) } }