swift - 如何为UIDocument添加通知观察者?

标签 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 显示了一个错误:

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

最佳答案

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

UIDocument.stateChangedNotification

关于swift - 如何为UIDocument添加通知观察者?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54081037/

相关文章:

ios - UIScrollView 及其子项 : why are they placed on top of each other? (AutoLayout)

ios - 在 Swift 中向自定义按钮添加闭包

iphone - 向 iphone/android app/webapp 发送通知有哪些选项?

android - 当我的应用程序处于前台时如何关闭通知图标?

android - 解析推送通知notify twice for Android

ios - PushNotification OneSignal 问题

ios - trailingSwipeActionsConfigurationForRowAt 不能稳定工作

ios - Interface Builder 中 UIButton 的活力效果

ios - 无法将 collectionView 导出添加到 nib 中的 UICollectionViewController

callback - 钛移动推送通知回调未触发