First, the object:
parameter of -addObserver:selector:name:object:
is the thing which will be posting the notification. If a notification of the specified name is posted by a different object, the notification center does not invoke your selector. Since your dictionary will never be posting NSFileHandleReadToEndOfFileCompletionNotification
(because dictionaries don't post notifications), your selector will never be invoked.
So, don't pass a dictionary as the object
. It doesn't do what you think. It's not a means of passing information in to the observing method.
You can use the more modern, block-based observer method to do this:
__block id observation = [[NSNotificationCenter defaultCenter] addObserverForName:NSFileHandleReadToEndOfFileCompletionNotification
object:[outputPipe fileHandleForReading]
queue:nil
usingBlock:^(NSNotification *note) {
// Do whatever you want to do in response to the notification here.
// You can access the completion_ variable directly.
[[NSNotificationCenter defaultCenter] removeObserver:observation];
observation = nil;
}];
You have to be careful to keep the observation object alive until the notification fires but also remove it and release it (by clearing the strong reference) once it does. I've shown that above.