Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I close/quit my app in macOS SwiftUI life cycle?

I want to know how can I close or quit my app? also I have some code for closing my app, but the code does not looks modern and updated to SwiftUI, do we got some new and better one?

import SwiftUI

@main
struct Work_Space_macOSApp: App {
    var body: some Scene {
        WindowGroup {

            VStack {

                Button("Close App") {
                    
                    // Do we have more SwifUI-ish code for closing App?
                    NSApplication.shared.keyWindow?.close()
                }
                
                Button("Quit App") {
                    // How can I quit the app?
                    
                }
                
            }
            .frame(width: 200, height: 200)
        }
    }
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

To terminate the application:

NSApplication.shared.terminate(nil)

There are still many, many features of AppKit that SwiftUI doesn’t support.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading