0

I need to be able to show a different view depending on IF statements but I am unable to figure it out:

Example:

if content == value1 { // go to view1 } if content == value2 { // go to view2 } 
7
  • 2
    if/else rather than separate if and == instead of = to start with Commented May 11, 2021 at 5:46
  • As @Joakim Danielson stated, make sure you're using the Comparison operator, which is ==. You use = to set a variable's value. Commented May 11, 2021 at 6:02
  • Sorry, forgot that in my example. For my actual code, my only problem is the navigation. Commented May 11, 2021 at 6:05
  • You have in no way described what your real problem is so you should add a more detailed explanation to your question and some more useful sample code Commented May 11, 2021 at 6:16
  • Question is unclear. in title you mention navigate within if and in contain show view according if statement. can you please clear me. Commented May 11, 2021 at 6:17

1 Answer 1

1

You can use if/else, like this:

import SwiftUI struct Test: View { @State private var something: Bool = false var body: some View { ZStack { if something { View1() } else { View2() } } } } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.