An extension to SwiftUI that will put terminateApplication() into the environment.
Download TerminateApplication.swift
and add the script to your project.
- We declare a
terminateApplication
environment value. - Then, we can call this wherever we want to terminate the application.
import SwiftUI
struct ContentView: View {
// 1
@Environment(\.terminateApplication) private var terminateApplication
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Hello, world!")
Button("Quit") {
// 2
terminateApplication()
}
}
.padding()
}
}
If you have been enjoying my free Swift script, please consider showing your support by buying me a coffee through the link below. Thanks in advance!