You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
975 B
40 lines
975 B
import Foundation
|
|
import SwiftUI
|
|
|
|
extension View {
|
|
@ViewBuilder func `if`<Content: View>(_ condition: Bool, _ modifier: (Self) -> Content) -> some View {
|
|
if condition {
|
|
modifier(self)
|
|
} else {
|
|
self
|
|
}
|
|
}
|
|
|
|
@ViewBuilder func either<Content: View>(_ condition: Bool, `true`: (Self) -> Content, `false`: (Self) -> Content) -> some View {
|
|
if condition {
|
|
`true`(self)
|
|
} else {
|
|
`false`(self)
|
|
}
|
|
}
|
|
}
|
|
|
|
extension Binding {
|
|
func map<T>(_ get: @escaping (Value) -> T) -> Binding<T> {
|
|
Binding<T>(
|
|
get: { get(self.wrappedValue) },
|
|
set: { _ in fatalError("Not implemented") }
|
|
)
|
|
}
|
|
|
|
func map<T>(
|
|
get: @escaping (Value) -> T,
|
|
set: @escaping (T) -> Value
|
|
) -> Binding<T> {
|
|
Binding<T>(
|
|
get: { get(self.wrappedValue) },
|
|
set: { self.wrappedValue = set($0) }
|
|
)
|
|
}
|
|
}
|