-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.

1
  • see this answer, you need opacity Commented Sep 1, 2021 at 16:37

1 Answer 1

1

You can do the same without else part:

if number != 1 {
    Text("Test")
}
Sign up to request clarification or add additional context in comments.

1 Comment

You may add the complete body, to see the context and to make it clear, that the statements are written in a ViewBuilder ;)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.