Blog 2022/3/21
<- previous | index | next ->
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);
}