In my code there is a rare instance where the observer will be removed a second time. Will this cause issues?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.