view sheet on first launch

Hi


I'm trying to display a sheet when the app first launches, similiar to when you upraded iOS to 13 and tapped say reminders.


But I'm struggling to get with working with SwiftUI, here is a snippet of the code. It essentially crashes the app.

import SwiftUI

struct ContentView: View {
    @State private var showingSheet = false

    var body: some View {
       return self.sheet(isPresented: $showingSheet) {
            RegisterHome()
        }
    }
}

struct RegisterHome: View {
    var body: some View {
        NavigationView {
            Text("Register")
                .navigationBarTitle("Register")
        }
    }
}


Any thoughts would be very much appreciated.


Thanks, Craig

Accepted Reply

Hi Claude31


I re-jigged a bit of code around to the following:


struct ContentView: View {
    @State private var showingSheet = true

    var body: some View {
        RequestHome().sheet(isPresented: $showingSheet) {
            RegisterHome()
        }
    }
}


This gives me the effect I was trying to achieve - a sheet display on launch which I'll conditionalize later on.


Craig

Replies

Where does it crash exactly ? What message ?

Hi Claude31


I re-jigged a bit of code around to the following:


struct ContentView: View {
    @State private var showingSheet = true

    var body: some View {
        RequestHome().sheet(isPresented: $showingSheet) {
            RegisterHome()
        }
    }
}


This gives me the effect I was trying to achieve - a sheet display on launch which I'll conditionalize later on.


Craig

Thanks for feedback. You can close the thread on your correct answer.


And if possible move the thread to SwiftUI.