The simplest way to avoid using an extra container like HStack
is to annotate your body
property as @ViewBuilder
, like this:
@ViewBuilder
var body: some View {
if user.isLoggedIn {
MainView()
} else {
LoginView()
}
}
More Related Contents:
- How to make a SwiftUI List scroll automatically?
- Deleting list elements from SwiftUI’s List
- Opt out of UISceneDelegate/SwiftUI on iOS
- Dynamically hiding view in SwiftUI
- Custom back button for NavigationView’s navigation bar in SwiftUI
- iOS 14 SwiftUI Keyboard lifts view automatically
- How to convert a View (not UIView) to an image?
- What is Geometry Reader in SwiftUI?
- SwiftUI dismiss modal
- Sheet inside ForEach doesn’t loop over items SwiftUI
- SwiftUI View and @FetchRequest predicate with variable that can change
- How do I modify the background color of a List in SwiftUI?
- Fetch data from CoreData for iOS 14 widget
- First item in a List is always selected
- How do I use UserDefaults with SwiftUI?
- Updating time text label each minute in WidgetKit
- How to refresh Widget data?
- Extra arguments at positions #11, #12 in call SwiftUI [duplicate]
- In SwiftUI, How do I increase the height of a button?
- How can I get text to wrap in a UILabel (via UIViewRepresentable) without having a fixed width?
- Deletable Table with TextField on SwiftUI
- Where is Info.plist in Xcode 13? (missing, not inside project navigator)
- How to use a @FetchRequest with the new searchable modifier in SwiftUI?
- SwiftUI: Send email
- SwiftUI hierarchical Picker with dynamic data crashes [duplicate]
- SwiftUI: How to implement a custom init with @Binding variables
- SwiftUI 2: the way to open view in new window
- Custom Button in SwiftUI List
- How we can get and read size of a Text with GeometryReader in SwiftUI?
- SwiftUI add inverted mask