didBecomeActiveNotification

didBecomeActiveNotification

我正在Xcode 10.1上开发一个macOS应用程序,目标是10.14。根据文档,应该有一个NSNotification.Name.didBecomeActiveNotification,但是生成失败,出现了一个Type 'NSNotification.Name?' has no member 'didBecomeActiveNotification'错误。我已经进口了可可,AppKit和Foundation。以下是相关代码:

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

怎么了?

最佳答案

它现在是NSApplication的类属性

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

10-08 15:40