0

Is it possible to do something such as:

Vstack {
   Text("Hello, World!")
}
   if Role == "administrator" {
   .offset(y: 15)
}

Doing this right now gives an error on the var body: some View { line.

4
  • yes its totally posible Commented Feb 5, 2022 at 21:02
  • how is it possible since I can't figure it out. Commented Feb 5, 2022 at 21:03
  • see my answer and git it done :) Commented Feb 5, 2022 at 21:10
  • Try a ternary operator inside the modifier, .offset(Role == "administrator" ? 15 : 0) Commented Feb 5, 2022 at 21:10

1 Answer 1

1

You can do like this

struct ContentView: View {
    @State private var Role: String = "administrator"
    
    var body: some View {
        VStack {
            Text("Hello, World!")
        }
        .offset(y: Role == "administrator" ? 15 : 0)
    }
}

read more here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.