Reputation: 71
I'm an experience C/C++ programmer but new to ObjC++. I'm trying to catch the NSWorkspacedidmountnofification in a Mac OSX project.
I added my callback to my app delegate interface.
- (void)mediaMounted:(NSNotification *)notification;
The implementation includes
- (void)mediaMounted:(NSNotification *)aNotification {
NSLog(@"mediaMounted volume change.");
}
In my applicationDidFinishLaunching, I add myself to the notification center.
NSNotificationCenter* ncenter = [[NSWorkspace sharedWorkspace] notificationCenter];
[ncenter addObserver: self
selector: @selector(mediaMounted)
name: NSWorkspaceDidMountNotification
object: nil];
However, when I run and mount the disk, I see:
2012-08-29 09:52:31.753 OSN[2203:903] -[OSNAppDelegate mediaMounted]: unrecognized selector sent to instance 0x101340af0
2012-08-29 09:52:31.756 OSN[2203:903] -[OSNAppDelegate mediaMounted]: unrecognized selector sent to instance 0x101340af0
I confirmed that Instance 0x101340af0 is my OSNAppDelegate self, but I don't understand what else I need to do so the selector is recognized.
Upvotes: 4
Views: 410
Reputation: 12566
Your selector should be:
mediaMounted:
not mediaMounted
.
Your implementation takes an NSNotification as a parameter, not nothing.
You can verify your selector via:
if( [self respondsToSelector:@selector(mediaMounted)] )
{
NSLog(@"Good to go");
}
Example:
// this selector
@selector(test)
// will call this method
- (void)test{ }
// but this selector, noting the :
@selector(test:)
// would call this method
- (void)test:(id)sender{ }
You can read about selectors here.
Upvotes: 2