Reputation: 417
Trying to understand what mistake I am doing with the following code.
This is to be a Mac application, Xcode version 12.4. My problem is that applicationDidFinishLaunching
never gets triggered.
import SwiftUI
@main
struct TestApp: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) var Delegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(aNotification: NSNotification) {
let alert = NSAlert.init()
alert.messageText = "Hello world"
alert.informativeText = "Information text"
alert.addButton(withTitle: "OK")
alert.addButton(withTitle: "Cancel")
alert.runModal()
}
}
Upvotes: 0
Views: 893
Reputation: 19014
You have typing mistake. It's not an "a" it's a "_"
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ notification: Notification) { //<here
let alert = NSAlert.init()
alert.messageText = "Hello world"
alert.informativeText = "Information text"
alert.addButton(withTitle: "OK")
alert.addButton(withTitle: "Cancel")
alert.runModal()
}
}
Upvotes: 2