If I register for the same event multiple times, will it do anything? Or will I need to unregister that many times? If the latter, how can I check to see if I’m already registered to receive a particular event?
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.
You will receive notifications multiple times. The docs claim there are some situations where you would want this, though I can’t think of any.
You can use
removeObserver:orremoveObserver:name:object:immediately before adding the observer, to ensure it isn’t added multiple times. There is nothing wrong with callingremoveObserver:with an object that isn’t actually observing a notification.Alternatively (and this is probably the highest performance and most reliable option) you could create your own
NSSetobject to store exactly what objects you’ve added to that specific notification, and check if the one you’re about to add a duplicate.