1
0

ConditionalApplicationModifier.swift 594 B

1234567891011121314151617181920212223
  1. extension View {
  2. public func `if`<Result: View>(
  3. _ condition: Bool,
  4. apply modifier: (Self) -> Result
  5. ) -> some View {
  6. if condition {
  7. EitherView<Self, Result>(modifier(self))
  8. } else {
  9. EitherView<Self, Result>(self)
  10. }
  11. }
  12. public func ifLet<Value, Result: View>(
  13. _ value: Value?,
  14. apply modifier: (Self, Value) -> Result
  15. ) -> some View {
  16. if let value {
  17. EitherView<Self, Result>(modifier(self, value))
  18. } else {
  19. EitherView<Self, Result>(self)
  20. }
  21. }
  22. }