Skip to content

Instantly share code, notes, and snippets.

@anupamchugh
Created May 7, 2020 08:04
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anupamchugh/182698f30f06d6b9a62956983cb5c3d2 to your computer and use it in GitHub Desktop.
Save anupamchugh/182698f30f06d6b9a62956983cb5c3d2 to your computer and use it in GitHub Desktop.
struct Anything<Wrapper : UIView>: UIViewRepresentable {
typealias Updater = (Wrapper, Context) -> Void
var makeView: () -> Wrapper
var update: (Wrapper, Context) -> Void
init(_ makeView: @escaping @autoclosure () -> Wrapper,
updater update: @escaping (Wrapper) -> Void) {
self.makeView = makeView
self.update = { view, _ in update(view) }
}
func makeUIView(context: Context) -> Wrapper {
makeView()
}
func updateUIView(_ view: Wrapper, context: Context) {
update(view, context)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment