OSXCocoa Window Without XCode or Interface Builder
OSXCocoa Window Without XCode or Interface Builder
glampert.com/2012/11-29/osx-window-without-xcode-and-ib
Sounds very simple doesn’t it? Well, like people say, hell is in the details.
The actual amount
of code required to do so is small, but the big issue was that
you just don’t find much official
Apple documentation and examples on the subject!
Since I am also a beginner with
Objective-C and Cocoa, it took me hours and hours of search
and research to finally be able
to open a simple application window on the Mac.
1/3
/*
* File: OSXWindow.m
*
* Brief:
*
* Compile with:
*/
#import "Cocoa/Cocoa.h"
// Autorelease Pool:
[NSApplication sharedApplication];
//
// Create a window:
//
// Style flags:
styleMask:windowStyle
backing:NSBackingStoreBuffered
defer:NO];
[window autorelease];
// Window controller:
[windowController autorelease];
[textView autorelease];
[window setContentView:textView];
2/3
// TODO: Create app delegate to handle system events.
[window orderFrontRegardless];
[NSApp run];
[pool drain];
return 0;
3/3