I would like to perform some cleanup at the end of a view controller\'s life, namely to remove an NSNotificationCenter
notification. Implementing dealloc<
removing observer is required before deallocation otherwise crash would happen. It can be done using
deinit {
// perform the deinitialization
print("deinit")
removeObserver(self, forKeyPath: kSelectedViewControllerKey, context: nil)
removeObserver(self, forKeyPath: kSelectedIndexKey, context: nil)
}