Question

I have list of objects in my iOS application, which observe some changes using NSNotificationCenter.

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onSomeChanges) 
                                                     name:@"SomeConstantNotificatioName" object:nil]; 

So when notification is posted, NSNotificationCenter calls onSomeChanges methods in the same order as addObserver methods were called.

The question is there any way to changed this order?

What I need is ability to call some adding observer method, which will insert needed observer as the first element of the observers list. So no matter in what order observers are added, some object will receive notification first.

Thank you

Was it helpful?

Solution

You can't change order of observers, even if you add them in order you want there is no guaranty that notification center calls them in right order. I suggest you to add one observer that require to be called first and then post another notification for others. This will be hard to debug later but you will be sure about order in this case

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top