如何为UIDocument添加通知观察器?

时间:2019-01-07 20:03:14

标签: swift notifications

private var documentObserver: NSObjectProtocol?

override func viewDidLoad() {
super.viewDidLoad()

documentObserver  = NotificationCenter.default.addObserver(
            forName: Notification.Name.UIDocumentStateChangedNotification ,
            object: document,
            queue: OperationQueue.main,
            using: { notification in
                print("docuemntState Changed to \(self.document!.documentState)")
            }
        )

}

我正在尝试这样做,但是Xcode向我显示错误:

  

类型'Notification.Name'(aka'NSNotification.Name')没有成员   'UIDocumentStateChangedNotification'

1 个答案:

答案 0 :(得分:0)

您要查找的通知名称是UIDocument的静态常量

UIDocument.stateChangedNotification