I found out how to create a window in Cocoa programmatically but can't figure out how to react to events. The window is not reacting to a Quit request or button click.

I tried adding the following controller and used setDelegate/setTarget without luck:

    @interface AppController : NSObject {
    }
    - (IBAction)doSomething:(id)sender;
    @end

    @implementation AppController
    - (IBAction)doSomething:(id)sender;
    {
        printf("Button clicked!\n");
    }
    @end

    int main(int argc, char **args){
        NSRect frame = NSMakeRect(0, 0, 200, 200);

        AppController *controller = [[AppController alloc] init];

>       [[NSApplication sharedApplication] setDelegate:controller];
        NSWindow* window  = [[NSWindow alloc] initWithContentRect:frame
                                            styleMask:NSBorderlessWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask
                                            backing:NSBackingStoreBuffered
                                            defer:NO];
        [window setBackgroundColor:[NSColor blueColor]];

        NSButton *button = [ [ NSButton alloc ] initWithFrame: NSMakeRect( 30.0, 20.0, 80.0, 50.0 ) ];
        [ button setBezelStyle:NSRoundedBezelStyle];
        [ button setTitle: @"Click" ];
>       [ button setAction:@selector(doSomething:)];
>       [ button setTarget:controller];
        [ [ window contentView ] addSubview: button ];

        [window makeKeyAndOrderFront:NSApp];

        [[NSRunLoop currentRunLoop] run];
        return 0;
    }
Edit
Report