Skip to content

Instantly share code, notes, and snippets.

@daltonclaybrook
Created July 16, 2019 20:04
Show Gist options
  • Save daltonclaybrook/e395115c21024d7e8a724838dddda501 to your computer and use it in GitHub Desktop.
Save daltonclaybrook/e395115c21024d7e8a724838dddda501 to your computer and use it in GitHub Desktop.
struct OptionalView<Value, Content: View>: View {
private let value: Value?
private let content: (Value) -> Content
init(_ value: Value?, content: @escaping (Value) -> Content) {
self.value = value
self.content = content
}
var body: AnyView {
if let value = value {
return AnyView(content(value))
} else {
return AnyView(EmptyView())
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment