In my code there is a rare instance where the observer will be removed a second time. Will this cause issues?
Asked
Active
Viewed 778 times
1
-
1This question is a little vague. Is it possible to provide some more details regarding how you pass, and receive notifications? Also, how you are adding and removing the object from the notification center? – 5StringRyan Aug 31 '12 at 19:21
-
this makes no sense. you say "the observer WILL be removed a second time". if you know it WILL be removed why can't you do something to avoid that? – jere Sep 04 '12 at 18:45
1 Answers
1
Yes. If you're not an observer and you try to remove yourself, your app will crash. There is no way to check if you're registered, so you'll have to create an ivar that flags whether you're added as an observer (or, perhaps even better, counts how many times you're added as an observer) and check the ivar before actually removing yourself.
EDIT: Turns out you can remove yourself before you're added, so I guess, although it's not a great design, it wouldn't matter much if you removed yourself twice.

Scott Berrevoets
- 16,921
- 6
- 59
- 80