0
votes

SwiftUI has these two modifiers:

.actionSheet(isPresented: $showActionPurchase) { () -> ActionSheet in

and

.sheet(isPresented: $showAlert,

one presents an action sheet and the other presents a sheet (?)

Why? What is the difference between these elements, if any?

1
Did you try them? - Roope
not yet because I am having problems understanding them. Care to explain? - Ronnie
I am unsure why trying them would be an issue. You will find basic examples of both by googling "swiftui sheet example" and "swiftui actionsheet example". - Roope
As a response to your comment below, nobody thinks everyone has to know everything or "hate downvotes" everybody that is not at the same level. You must understand that your question would have been solved by very basic google searches, or by simply running the functions. There is no expectation to know anything and certainly no hate, but only the expectation of effort to solve it before asking. And when simply running the functions would have solved your question, it is easily interpreted as lack or effort, which leads to downvotes. Best of luck on your learning journey. - Roope

1 Answers

3
votes

sheet used for showing some view modal-way, but actionSheet is kind of alert view! they are very diffrent topic!

    import SwiftUI

struct ContentView: View {
    
    @State var showSheet = false
    @State var showActionSheet = false
    
    let appActionSheet = ActionSheet(title: Text("ActionSheet"), message: Text("I am an ActionSheet"), buttons: [
        .default(Text("some text")),
        .cancel()
    ])
    
    
    var body: some View {

        VStack
        {
            
            Button("show sheet") {showSheet.toggle()}.padding()
            
            Button("show actionSheet") {showActionSheet.toggle()}.padding()
            
            
        }.font(Font.title.bold())
        .sheet(isPresented: $showSheet, content: {sheetView()})
        .actionSheet(isPresented: $showActionSheet, content: {appActionSheet})

    }
}



struct sheetView: View {
    var body: some View {
        
        ZStack
        {
            Color.red
            Text("I am sheet view")
        }.ignoresSafeArea()
    }
}

enter image description here

enter image description here