Type 'Notification.Name' (aka 'NSNotification.Name') has no member 'UIApplication'

mathias merlot picture mathias merlot · Jul 22, 2018 · Viewed 25.9k times · Source

First it said that

'UIApplicationDidEnterBackground' has been renamed to 'UIApplication.didEnterBackgroundNotification'

and when I dot it,it said

Type 'Notification.Name' (aka 'NSNotification.Name') has no member 'UIApplication'

func listenForBackgroundNotification() {
    observer = NotificationCenter.default.addObserver(forName: Notification.Name.UIApplicationDidEnterBackground, object: nil, queue: OperationQueue.main) { [weak self] _ in
        if let weakSelf = self {
            if weakSelf.presentedViewController != nil {
                weakSelf.dismiss(animated: true, completion: nil)
            }
            weakSelf.descriptionTextView.resignFirstResponder()

        }
    }
}

Answer

matt picture matt · Jul 23, 2018

Change

forName: Notification.Name.UIApplicationDidEnterBackground

to

forName: UIApplication.didEnterBackgroundNotification