My app has several notifications and observers to refresh the views when a user adds or deletes data.
Should I use a notification and observer for each type of data interaction? For example:
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "categoryAdded"), object: nil)
And then for each notification:
NotificationCenter.default.addObserver(self, selector: #selector(self.refresh), name: NSNotification.Name(rawValue: "categoryAdded"), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(self.refresh), name: NSNotification.Name(rawValue: "transactionAdded"), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(self.refresh), name: NSNotification.Name(rawValue: "transactionDeleted"), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(self.refresh), name: NSNotification.Name(rawValue: "transactionEdited"), object: nil)
Or can I just use a single value:
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "dataUpdated"), object: nil)
And then use a single observer:
NotificationCenter.default.addObserver(self, selector: #selector(self.refresh), name: NSNotification.Name(rawValue: "dataUpdated"), object: nil)