Sorry if this is an answered question but 'Swift' 'App' and 'Protocol' are all too generic terms to warrant a good result.
I have socket emulator app that I use for testing that has a App struct with the server as a property:
@main
struct RelayEmulatorApp: App {
var socketServer : SocketServer
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
}
And then in my appDelegate I override applicationWillTerminate where I would like to gracefully close the socket server. I'm finding since the socketServer's deinit has the calls to NIO's syncShutdownGracefully which is not called on app termination, I have to call it explicitly in AppDelegate (the OS apparently is slow to close the socket for a terminated process when the process doesn't do so--I think).
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationWillTerminate(_ notification: Notification) {
}
}
But how in the AppDelegate can I reference the instance of the App struct (which I imagine is being instantiated by the @main annotation) and thus its properties to gracefully shutdown the socket?