Skip to content

Instantly share code, notes, and snippets.

@cellularmitosis
Last active Mar 22, 2022
Embed
What would you like to do?
A first Cocoa app for OS X Tiger 10.4 using Xcode 3.1.4

Blog 2022/3/21

<- previous | index

A first Cocoa app for OS X Tiger 10.4 using Xcode 3.1.4

Getting my feet wet with Cocoa development for PowerPC Macs.

This app simply draws a blue window. Note that this does not require using Interface Builder.

Create a new Xcode project, then paste this into main.m:

#import <Cocoa/Cocoa.h>


@interface BlueView: NSView
@end

@implementation BlueView
- (void)drawRect:(NSRect)rect {
    [[NSColor blueColor] setFill];
    NSRectFill(rect);
    [super drawRect:rect];
}
@end


@interface AppListener: NSObject
- (void)applicationDidBecomeActive;
@end

@implementation AppListener

- (void)applicationDidBecomeActive {
    NSLog(@"did become active.");
    NSWindow* window = [[NSApplication sharedApplication] keyWindow];
    NSLog(@"window: %@", window);
    NSView* view = [[BlueView alloc] init];
    [window setContentView:view];
}

@end


int main(int argc, char *argv[])
{
    AppListener* listener = [[AppListener alloc] init];
    [[NSNotificationCenter defaultCenter]
        addObserver:listener
        selector:@selector(applicationDidBecomeActive)
        name:NSApplicationDidBecomeActiveNotification object:nil];
    return NSApplicationMain(argc,  (const char **) argv);
}

screenshot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment