Skip to content

Instantly share code, notes, and snippets.

@codebrainz
Created March 7, 2012 06:45
Show Gist options
  • Select an option

  • Save codebrainz/1991520 to your computer and use it in GitHub Desktop.

Select an option

Save codebrainz/1991520 to your computer and use it in GitHub Desktop.
Simple Mac application
/*
* A very basic Cocoa application.
*
* Save as "main.m" and compile in Terminal.app with:
* clang -o test main.m -framework AppKit -fobj-c-arc
*/
#import <AppKit/AppKit.h>
@interface TestView : NSView <NSWindowDelegate>
- (void)drawRect:(NSRect)rect;
@end
@implementation TestView
- (void)drawRect:(NSRect)rect
{
[[NSColor blueColor] set];
NSRectFill([self bounds]);
}
- (void)windowWillClose:(NSNotification*)notification
{
[[NSApplication sharedApplication] terminate:self];
}
@end
int main(int argc, char *argv[])
{
NSApplication *NSApp = [NSApplication sharedApplication];
NSRect frame = NSMakeRect(100.0, 100.0, 320.0, 240.0);
NSWindow *window = [[NSWindow alloc]
initWithContentRect:frame
styleMask:NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask
backing:NSBackingStoreBuffered
defer:NO];
[window setTitle:@"Testing"];
TestView *view = [[TestView alloc] initWithFrame:frame];
[window setContentView:view];
[window setDelegate:view];
[window makeKeyAndOrderFront:nil];
[NSApp run];
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment