-1

I have one SwiftUI view which i want to hide on specific condition. Also I want empty space hidden should not remove the view space. is there any way to do this in SwiftUI?

for ex. bellow Text i want to hide if number == 1 and show if number == 0

Text("Test")
  .hidden()

how to hive condition in SwiftUI

I can do bellow but its repetitive code.

if number == 1 {
    Text("Test")
      .hidden()
}
else {
   Text("Test")
}

Please suggest better solution.

Thank you for help.

Rahul
  • 537
  • 1
  • 7
  • 19

1 Answers1

1

You can do the same without else part:

if number != 1 {
    Text("Test")
}
Phil Dukhov
  • 67,741
  • 15
  • 184
  • 220
  • You may add the complete body, to see the context and to make it clear, that the statements are written in a ViewBuilder ;) – CouchDeveloper Sep 01 '21 at 13:25