Search code examples
swiftmacosnsnotificationsnotificationcenter

NSNotification.Name.didBecomeActiveNotification not found


I'm working on a macOS app on Xcode 10.1 with a 10.14 deployment target. According to the documentation there should be a NSNotification.Name.didBecomeActiveNotification, but the build fails with a Type 'NSNotification.Name?' has no member 'didBecomeActiveNotification' error. I have imported Cocoa, AppKit and Foundation. Here is the relevant code:

NotificationCenter.default.addObserver(forName: .didBecomeActiveNotification, object: nil, queue: nil) { notification in
    print("\(notification)")
}

What is the problem?


Solution

  • It's now a class property of NSApplication

    NotificationCenter.default.addObserver(forName: NSApplication.didBecomeActiveNotification, object: nil, queue: nil) { notification in