在 Swift 3 中,我使用以下代码注册了睡眠和唤醒通知:
let notificationCenter = NSWorkspace.shared.notificationCenter
notificationCenter.addObserver(self, selector: #selector(AppDelegate.sleepListener), name: NSNotification.Name.NSWorkspaceWillSleep, object: nil)
notificationCenter.addObserver(self, selector: #selector(AppDelegate.wakeUpListener), name: NSNotification.Name.NSWorkspaceDidWake, object: nil)
但是在迁移到 Swift 4 后,我在应用建议的修复程序后收到此错误:
Type 'NSNotification.Name' has no member 'NSWorkspace'
我如何在 Swift 4 中做到这一点?