Skip to content

Instantly share code, notes, and snippets.

@JadenGeller
Created February 16, 2021 07:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JadenGeller/694d855545b6419afa7fd00562a6a3bc to your computer and use it in GitHub Desktop.
Save JadenGeller/694d855545b6419afa7fd00562a6a3bc to your computer and use it in GitHub Desktop.
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)
}
}
@JadenGeller
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment