Created
July 19, 2012 20:32
-
-
Save bellbind/3146586 to your computer and use it in GitHub Desktop.
[macosx][objective-c]Make cocoa app without Xcode
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
// clang -framework Cocoa app.m -o app | |
// ./app | |
#import <Cocoa/Cocoa.h> | |
int main() | |
{ | |
[NSAutoreleasePool new]; | |
id app = [NSApplication sharedApplication]; | |
[app setActivationPolicy:NSApplicationActivationPolicyRegular]; | |
NSRect frame = NSMakeRect(0, 0, 300, 300); | |
id window = | |
[[[NSWindow alloc] initWithContentRect:frame | |
styleMask:NSTitledWindowMask | |
backing:NSBackingStoreBuffered | |
defer:NO] autorelease]; | |
[window cascadeTopLeftFromPoint:NSMakePoint(10, 10)]; | |
[window setTitle:@"Hello"]; | |
[window makeKeyAndOrderFront:nil]; | |
id button = [[[NSButton alloc] initWithFrame:frame] autorelease]; | |
[button setTarget:app]; | |
[button setAction:@selector(terminate:)]; | |
[button setTitle:@"Quit"]; | |
[[window contentView] addSubview:button]; | |
[app activateIgnoringOtherApps:YES]; | |
[app run]; | |
return 0; | |
} |
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
// clang -framework Cocoa -framework WebKit webkit.m -o webkit | |
// ./webkit | |
#import <Cocoa/Cocoa.h> | |
#import <WebKit/WebKit.h> | |
int main() | |
{ | |
[NSAutoreleasePool new]; | |
id app = [NSApplication sharedApplication]; | |
[app setActivationPolicy:NSApplicationActivationPolicyRegular]; | |
NSRect frame = NSMakeRect(0, 0, 640, 480); | |
int mask = NSTitledWindowMask | NSClosableWindowMask; | |
id window = | |
[[[NSWindow alloc] initWithContentRect:frame | |
styleMask:mask | |
backing:NSBackingStoreBuffered | |
defer:NO] autorelease]; | |
[window cascadeTopLeftFromPoint:NSMakePoint(10, 10)]; | |
[window setTitle:@"Hello"]; | |
[window makeKeyAndOrderFront:nil]; | |
id nc = [NSNotificationCenter defaultCenter]; | |
[nc addObserver:app | |
selector:@selector(terminate:) | |
name:NSWindowWillCloseNotification | |
object:window]; | |
id webview = [[[WebView alloc] initWithFrame:frame] autorelease]; | |
id url = [NSURL URLWithString:@"http://example.com/"]; | |
id req = [NSURLRequest requestWithURL:url]; | |
[[webview mainFrame] loadRequest:req]; | |
[[window contentView] addSubview:webview]; | |
[app activateIgnoringOtherApps:YES]; | |
[app run]; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you know of any resources that I could use to learn how to code Mac stuff this way? I've been searching for hours and haven't come up with anything besides this code (which I am now studying intently, lol) and one other GitHub repo
Thanks!
Hayden