添加观察者

时间:2020-10-16 17:05:56

标签: ios swift

我添加了以下观察者

NotificationCenter.default.addObserver(self, selector:#selector(handleCourseCompleted(_:)), name: NSNotification.Name ("com.course.completed"), object: nil)
        

这是如何删除它们

deinit {
   NotificationCenter.default.removeObserver(self)
}

1 个答案:

答案 0 :(得分:2)

如果您的应用程序无法在iOS 8或更早版本上运行,则完全不需要删除观察者。通知中心对其进行了ARC弱引用,并且self消失后也不会发生任何问题。