Created
June 15, 2013 17:28
-
-
Save divanvisagie/5788849 to your computer and use it in GitHub Desktop.
A snippet with different usage examples in NodObjC. Not all of this works but the concepts are mainly correct
This file contains 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
var $ = require( 'NodObjC' ); | |
// First you import the "Foundation" framework | |
$.import( 'Foundation' ); | |
$.import( 'Cocoa' ); | |
// Setup the recommended NSAutoreleasePool instance | |
var pool = $.NSAutoreleasePool( 'alloc' )( 'init' ); | |
// NSStrings and JavaScript Strings are distinct objects, you must create an | |
// NSString from a JS String when an Objective-C class method requires one. | |
var s = 'dude'; | |
var string = $.NSString( 'stringWithUTF8String', 'Hello Objective-C World!' ); | |
$.NSLog( $(s) ); | |
console.log( $(s) ); | |
// Print out the contents (toString() ends up calling [string description]) | |
console.log( string ); | |
var frame = $.NSMakeRect( 0, 0, 200, 200 ); | |
var win = $.NSWindow( 'alloc' )( 'initWithContentRect' , frame , | |
'styleMask' , $.NSBorderlessWindowMask , | |
'backing' , $.NSBackingStoreBuffered, | |
'defer' , 'NO' ); | |
win( 'setBackgroundColor', $.NSColor( 'blueColor' ) ); | |
win( 'makeKeyAndOrderFront' , $.NSApp ); | |
setTimeout((function() { | |
/* drain the pool because we are done */ | |
// pool( 'drain' ); | |
}), 5000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment