특정 이벤트를 발생 시키면 같은 Notification이 여러번 호출되는 버그 발견. NotificationCenter에 같은 Notification을 가지고 있는 옵저버를 계속 추가해줘서 발생하는 문제. 옵저버 중복 방지를 위해 옵저버를 제거하여 해결하자.
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true)
// 옵저버 추가
NotificationCenter.default.addObserver(self, selector: #selector(self.clickNumberNotification(_:)), name: ClickNumberNotification , object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(self.optionNotification(_:)), name: OptionNotification, object: nil)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(true)
// 모든 옵저버 제거
NotificationCenter.default.removeObserver(self)
// 특정 옵저버 제거
/*NotificationCenter.default.removeObserver(self, name: ClickNumberNotification, object: nil)
NotificationCenter.default.removeObserver(self, name: OptionNotification, object: nil)/*
}