I'm trying to write a Mac OS swift application that perform some processing each time a file is added to a directory (std folder automation is very slow ...). I want the application to run in background without GUI.
I created an AppDelegate.swift with an applicationDidFinishLaunching function which seems to be never called.
As a newbie I'm completely struggling : could someone help or guide me to any relevant resource (book, blog ...)
Thx in advance
You seem to be on roughly the right track.
applicationDidFinishLaunching function which seems to be never called.
The code you posted is using SwiftUI. applicationDidFinishLaunching()
is an AppKit mechanism. You can opt into that using NSApplicationDelegateAdaptor
. However, in this case that’s likely to be overkill. Rather, set things up in your app’s initialiser:
@main
struct MyShinyNewApp: App {
init() {
… set things up here …
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
ps Your snippet included some date formatting code that’s likely like to be wrong [1]. If you want a fixed-format date in Swift, use the Date.VerbatimFormatStyle
.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
[1] QA1480 NSDateFormatter and Internet Dates explains why.