Dear All,
In my application's backend (non-UI), I use NSNotificationCenter for communication across various modules.
Ideally I should be register for notification by calling addObserver in the init of the class and removeObserver function in the dealloc method.
But I want to restrict the registration and removal of the notification hence do it at a different point of time.
Occasionally due to my backend application logic, I happen to call again addObserver before calling removeObserver for the same notification. This will results in a crash when I try to post for that notification.
Code used to remove an registered notification.
So I was thinking of ALWAYS CALLING removingObserver before calling addObserver such that I can be absolutely sure that only one instance of the notification is registered.
This will result in removeObserver being called when no notification was being added at all.
It is safe to do so? Are there any drawbacks etc because of this logic?
Thanks in advance.
Regards.
In my application's backend (non-UI), I use NSNotificationCenter for communication across various modules.
Ideally I should be register for notification by calling addObserver in the init of the class and removeObserver function in the dealloc method.
But I want to restrict the registration and removal of the notification hence do it at a different point of time.
Occasionally due to my backend application logic, I happen to call again addObserver before calling removeObserver for the same notification. This will results in a crash when I try to post for that notification.
Code used to remove an registered notification.
Code:
[[NSNotificationCenter defaultCenter] removeObserver:self];
So I was thinking of ALWAYS CALLING removingObserver before calling addObserver such that I can be absolutely sure that only one instance of the notification is registered.
This will result in removeObserver being called when no notification was being added at all.
It is safe to do so? Are there any drawbacks etc because of this logic?
Thanks in advance.
Regards.