Skip to content

Instantly share code, notes, and snippets.

@Jpunt
Created June 6, 2019 06:58
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 Jpunt/42e49b65a7a3e63b25e3488febc5816f to your computer and use it in GitHub Desktop.
Save Jpunt/42e49b65a7a3e63b25e3488febc5816f to your computer and use it in GitHub Desktop.
struct IfLet<T, Out: View>: View {
let value: T?
let produce: (T) -> Out
init(_ value: T?, produce: @escaping (T) -> Out) {
self.value = value
self.produce = produce
}
var body: some View {
Group {
if value != nil {
produce(value!)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment