How to add if else statement on padding? SwiftUI

I want to set the padding to -15 only when showBar = false, how do i add the condition for this inside padding parameters?
This is for macOS 10.15 app.

@State private var showBar = true

          VStack {
          WebView          
            }
            .frame(maxWidth: .infinity, maxHeight: .infinity)
            .edgesIgnoringSafeArea(.all)
            .padding(.top, -15)

>Solution :

Use ternary operator right inside modifier, like

.frame(maxWidth: .infinity, maxHeight: .infinity)
.edgesIgnoringSafeArea(.all)
.padding(.top, showBar ? 0 : -15)  // << here !!

Leave a Reply