Right now the API doesn’t seem to provide a way to detect if an observer has already been added for a particular NSNotification. What’s the best way to avoid adding multiple NSNotification observers other than maintaining a flag on your end to keep track? Has anyone already created a category to facilitate this?
Share
One way to prevent duplicate observers from being added is to explicitly call removeObserver for the target / selector before adding it again. I imagine you can add this as a category method:
This assumes that the you will only add one unique observer to each target for any notification name, as it will remove any existing observers for that notification name.