I've been trying to play with Swift 3, but I am unable to get started. The following code is compiling, however it does not log anything. Looks like applicationDidFinishLaunching
is not being called. Am I missing some critical piece here?
Sources/main.swift:
import AppKit
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(aNotification: NSNotification) {
NSLog("application start")
}
}
NSApplication.shared()
NSApp.setActivationPolicy(.regular)
let controller = AppDelegate()
NSApp.delegate = controller
NSApp.run()
p.s. There is a similar question about applicationDidFinishLaunching
being called but not printing anything. I believe that this is not the case, as having window.orderFrontRegardless()
instead of logging also has no effect for me.
System Version: OS X 10.11.6
> swift --version
Apple Swift version 3.0 (swiftlang-800.0.43.6 clang-800.0.38)
Target: x86_64-apple-macosx10.9
If you want to implement Objective-C protocols in Swift 3, you need to use _
indicating the method has no label for the first parameter.
func applicationDidFinishLaunching(_ aNotification: Notification) {
(UPDATE)
Sorry, in my first code, I have forgotten to to replace NSNotification
with Notification
. (Thanks, Leo Dabus.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With