Created
August 22, 2021 14:21
-
-
Save ANSCoder/23f173ffd96d41606d36060d35e6c359 to your computer and use it in GitHub Desktop.
Unwrap values inside the SwiftUI `View`
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
// | |
// UnwrapUtil.swift | |
// Grocers | |
// | |
// Created by Anand Nimje on 08/09/20. | |
// Copyright © 2020 Anscoder. All rights reserved. | |
// | |
import SwiftUI | |
struct Unwrap<Value, Content: View>: View { | |
private let value: Value? | |
private let contentProvider: (Value) -> Content | |
init(_ value: Value?, | |
@ViewBuilder content: @escaping (Value) -> Content) { | |
self.value = value | |
self.contentProvider = content | |
} | |
var body: some View { | |
value.map(contentProvider) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uses -
Working with the Optionals type models inside the SwiftUI