Note that there are some explanatory texts on larger screens.

plurals
  1. PONSNotificationCenter Scope definition
    text
    copied!<p>So I'm new to NSNotifications, I am wondering what the scope is. I.e. If I have an Application Delegate Class, and it is the receiver of a notification:</p> <pre><code>-(id)init { [ super init]; if (!self) return nil; // Add to our notification [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveUpdateRequest:) name:@"RequestStatusUpdate" object:nil]; return self; } </code></pre> <p>And has this method run on receive:</p> <pre><code>- (void) receiveUpdateRequest:(NSNotification *) notification { // Check the Notification Name if ([[notification name] isEqualToString:@"RequestStatusUpdate"]){ NSLog (@"Recieved Update Status!"); } else { NSLog(@"Recieved Notification: %@",[notification name]); } } </code></pre> <p>Can I post a notification like so:</p> <pre><code>[[NSNotificationCenter defaultCenter] postNotificationName:@"RequestStatusUpdate" object:self]; </code></pre> <p>From another object instance any where in my App?</p> <p>Even for instance an object that instantiated by virtue of a NIB being loaded:</p> <pre><code>summaryWindow = [[SummaryWindowController alloc] initWithWindowNibName:@"SummaryWindow" owner:globalStatusController]; </code></pre> <p>Do I have to have anything else configured in my summaryWindow Class to be able to call the postNotificationName method. </p> <p>Or put a different way is the [NSNotificationCenter defaultCenter] global for all instances of all objects in my Application, I would assume thats how its suppose to work but currently when I call this method via an IBAction in my SummaryWindow , the notification does not seemed to be received.</p> <p>I have tested both [NSThread currentThread] and the default Notification center and it does look like I'm in the thread and the same notification center ( which I think is always global). I am only looking into the thread thing as its come up on a few other threads.</p> <pre><code>2011-08-22 20:57:11.452 AppName[23102:1307] Using Default Notification Center: &lt;CFNotificationCenter 0x10012c900 [0x7fff7d302ea0]&gt; 2011-08-22 20:57:20.366 AppName[23102:1307] Using Default Notification Center: &lt;CFNotificationCenter 0x10012c900 [0x7fff7d302ea0]&gt; </code></pre>
 

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