Created
March 7, 2012 06:45
-
-
Save codebrainz/1991520 to your computer and use it in GitHub Desktop.
Simple Mac application
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * 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