Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
106 lines (75 sloc) 3.23 KB


The Objective-C ⇆ NodeJS bridge

NodObjC exposes the Objective-C runtime to NodeJS in a high-level, easy to use fashion. It uses the BridgeSupport files to dynamically generate an API from an Objective-C "Framework" at runtime, and uses node-ffi to dynamically interact with Objective-C's runtime.

Essentially, NodObjC is similar in nature to the other popular Objetive-C scripting bridges:

So you can write Objective-C based applications entirely with Node and JavaScript! Eventually even iOS native apps as well! So what are you waiting for? Get to coding!

Note: This lib is still very much under development. It is not ready for primetime quite yet. Watch this project to follow the updates!

Hello World

var $ = require('NodObjC')

// First you need to "import" the Framework

// 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 string = $.NSString('stringWithUTF8String', 'Hello Objective-C World!')

// Print out the contents (calling [string description])
console.log('%s', string)
//   → Prints "Hello Objective-C World!"



This module offers a bi-directional bridge between NodeJS and the Objective-C runtime. What does that mean exactly? Well due to the design of the Objective-C runtime, it is possible to port the entire API to other languages. There are quite a few bridges for Obj-C so one for node was a necessity.

So with this module, you get access to all of the Objective-C APIs, but you invoke them through JavaScript. Obj-C has a concept of "message passing" to invoke methods on objects. The way that you pass messages around is probably a little bit different than the kind of JavaScript you're used to:

// In JavaScript, you invoke a function on an object like:

Compared to:

// In NodObjC, you send a message to an object like:
obj('func', arg)

In Objective-C, the names of methods are part of the arguments that you pass along, so let's look at a method that takes more than one argument:

array('insertObject', obj, 'atIndex', 5)

So the even numbered arguments are the parts of the method name that will be invoked, and the odd numbered arguments are the Obj-C arguments themselves. In the above example, the insertObject:atIndex: function will be invoked.

In NodObjC, not only is the Objective-C runtime exposed, but so are the corresponding C functions that usually go along with these APIs (thanks to BridgeSupport). So for example, we can make an NSRect by calling the NSMakeRect() C function:

$.NSMakeRect(5, 10, 8, 30)
// -> NSRect struct

There's literally thousands of other Objective-C resources and tutorials out there, especially Apple's offial documentation. So hopefully you get the gist of it here.

Jump to Line
Something went wrong with that request. Please try again.