Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes, there is a side effect I can think of. Let me explain it.</p> <p>The method you talk about was actually defined in NSNotification.h as below:</p> <ul> <li>(void)postNotificationName:(NSString *)notificationName object:(id)notificationSender</li> </ul> <p>The first parameter notificationName stands for the name of the notification. The second parameter notificationSender stands for the object posting the notification.</p> <p>Yes, any object can be a notification sender, even nil can be.</p> <p>In terms of observering the notification(to became a observer of a specific notification), we got to know another method defined in NSNotification:</p> <ul> <li>(void)addObserver:(id)notificationObserver selector:(SEL)notificationSelector name:(NSString *)notificationName object:(id)notificationSender</li> </ul> <p>As you can see, the last parameter is notificationSender(the object whose notifications the observer wants to receive). </p> <p>So right now, the <strong>side effect</strong> is apparently. Let me explain it in detail. There are three controllers A, B, C.for example. The controller A post a notification helloEveryone. The controller B also post a notification helloEveryone.<br> In C controller, if you place a statement like below:</p> <p>[[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(helloEveryOne) name:@"helloEveryone" object:nil]</p> <p>Then you will receive two helloEveryone from controller A and controller B. if you place a statement like this:</p> <p>[[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(helloEveryOne) name:@"helloEveryone" object:controllerA]</p> <p>Then you will receive only one helloEveryone from controller A.</p> <p>The <strong>self</strong> surely is not a nil notification sender as long as it can post a notification, but use another object as a notification sender, may be it is a nil object. And the observer's behave is different in terms of that whether notification sender is nil or not.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload