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 显示了一个错误:
Type 'Notification.Name' (aka 'NSNotification.Name') has no member 'UIDocumentStateChangedNotification '
最佳答案
您要查找的通知名称是UIDocument
的静态常量
UIDocument.stateChangedNotification
关于swift - 如何为UIDocument添加通知观察者?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54081037/