i’m new to Cocoa and I’m having a little trouble with a sample app i’m writing :
@implementation DeviceDetection
- (id) init {
self = [super init];
if (self) {
notCenter = [[NSWorkspace sharedWorkspace] notificationCenter];
[notCenter addObserver:self
selector:@selector(discMounted:)
name:@"NSWorkspaceDidMountNotification"
object:[NSWorkspace sharedWorkspace]]; // Register for all notifications
}
return self;
}
- (void)discMounted:(NSNotification *)notification
{
NSLog(@"COUCOU");
}
@end
#import <Foundation/Foundation.h>
@interface DeviceDetection : NSObject {
NSNotificationCenter *notCenter;
}
- (void) discMounted:(NSNotification *)notification;
@end
@implementation AppDelegate
@synthesize window = _window;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
DeviceDetection* d = [[DeviceDetection alloc] init];
[d value];
}
@end
With that piece of code i’m getting a the following error when I plug-in a USB drive :
[NSRunLoop discMounted:]: unrecognized selector sent to instance 0x10054c5a0
Any reason why ?
Thx
You need to define
deallocmethod ofDeviceDetection–EDIT 1 –
Above error occurs because you haven’t defined
valueinDeviceDetectionclass.