I'm currently trying learning Cocoa and I am not sure if I understand that correctly... It's about delegates and controllers.

At first: What's the difference between the two? Sometimes I see code where a class is called AppController, sometimes - with more or less the same content - AppDelegate.

So, if I understand it correctly, a delegate is a simple object that receives messages when a certain event occurs. For example:

@interface WindowController : NSObject <NSWindowDelegate>
@end

@implementation WindowController
- (void)windowDidMiniaturize:(NSNotification *)notification {
    NSLog(@"-windowDidMiniaturize");
}
@end

Now, I use this code to make it a delegate of my window:

@interface TryingAppDelegate : NSObject <NSApplicationDelegate> {
    NSWindow *window;
}

@property (assign) IBOutlet NSWindow *window;
@property (retain) WindowController *winController;

@end

With the following implementation:

@implementation TryingAppDelegate

@synthesize window;
@synthesize winController;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    NSLog(@"-applicationDidFinishLaunching:");

    self.winController = [[WindowController alloc] init];
    [window setDelegate:winController];

    [self.winController release];
}

@end

And now, whenever I minimize window, it will send a -windowDidMiniaturize: message to WindowController. Do I have that right?

If so, why don't you just subclass NSWindow rather than bothering with an additional class you have to take care of?

Edit
Report