Created
February 16, 2021 07:38
-
-
Save JadenGeller/694d855545b6419afa7fd00562a6a3bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Combine | |
import SwiftUI | |
struct SubscriberView<Publisher: Combine.Publisher>: View where Publisher.Output: View, Publisher.Failure == Never { | |
@State var view: Publisher.Output | |
let publisher: Publisher | |
var body: some View { | |
view.onReceive(publisher) { newView in | |
self.view = newView | |
} | |
} | |
} | |
extension Publisher where Output: View, Failure == Never { | |
func view(initialView: Output) -> SubscriberView<Self> { | |
.init(view: initialView, publisher: self) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I found a Swift package that seems decent: https://github.com/denizcoskun/SubscriberView/blob/master/Sources/SubscriberView/SubscriberView.swift