Created
July 16, 2019 20:04
-
-
Save daltonclaybrook/e395115c21024d7e8a724838dddda501 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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