How to interrupt, delay or stop a MacOS SwiftUI App from terminating
To show an alert pop-up that delays a MacOS app from closing (i.e. closing when a user quits), create a custom App Delegate and implement in the App struct.
The following tutorial shows code from our upcoming app Object Capture Pro. If you wish to be updated on the progress and release of this app, please subscribe using the link below.
Step One: Create the Delegate
In your app, create a new file called AppDelegate and paste in the code below.
Step Two: Implement the Delegate in the App
Within the main App struct of the project, add the line below to implement the delegate.
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
Step Three: Test
Run the code and attempt to quit the app.
The alert should show up when you do.
Looking to learn more about SwiftUI, Swift, Design and Technology?
Search our blog to learn more about Swift, SwiftUI, design and technology.