# NodObjC

> The Node.js ⇆ Objective-C bridge

Latest version **1.0.0** (published 2014-08-19) · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install NodObjC
pnpm add NodObjC
yarn add NodObjC
bun add NodObjC
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2014-08-19 |
| First published | 2011-08-14 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1420 |
| Author | Nathan Rajlich |
| Maintainers | TooTallNate, tootallnate |
| Keywords | obj, objective, c, mac, apple, ios, osx, cocoa, ffi, bridge |

## Links

- npm: https://www.npmjs.com/package/NodObjC
- Repository: https://github.com/TooTallNate/NodObjC
- Issues: https://github.com/TooTallNate/NodObjC/issues
- npm.io page: https://npm.io/package/NodObjC

## Dependencies (4)

- [ffi](https://npm.io/package/ffi.md) ~1.2.7
- [ref](https://npm.io/package/ref.md) ~0.3.2
- [debug](https://npm.io/package/debug.md) *
- [ref-struct](https://npm.io/package/ref-struct.md) 0.0.6

## Alternatives

- [@gemini-wallet/core](https://npm.io/package/@gemini-wallet/core.md) — 515.6K weekly downloads
- [utility](https://npm.io/package/utility.md) — 416.6K weekly downloads
- [@primno/dpapi](https://npm.io/package/@primno/dpapi.md) — 7.2K weekly downloads
- [pi-readseek](https://npm.io/package/pi-readseek.md) — 3.7K weekly downloads
- [@emilia-protocol/verify](https://npm.io/package/@emilia-protocol/verify.md) — 1.1K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2014-08-19
- 0.0.15 — 2013-04-01
- 0.0.14 — 2012-09-19
- 0.0.13 — 2012-09-18
- 0.0.12 — 2012-07-23
- 0.0.11 — 2012-04-22
- 0.0.10 — 2012-04-12
- 0.0.9 — 2011-12-19
- 0.0.8 — 2011-09-29
- 0.0.7 — 2011-09-15
- 0.0.6 — 2011-09-05
- 0.0.5 — 2011-08-26
- 0.0.4 — 2011-08-17
- 0.0.3 — 2011-08-14
- 0.0.2 — 2011-08-14
- … 1 more at https://npm.io/package/NodObjC/versions

## README

NodObjC
=======
### The [Node.js][] ⇆ [Objective-C][ObjCWikipedia] bridge
[![Build Status](https://travis-ci.org/TooTallNate/NodObjC.svg?branch=master)](https://travis-ci.org/TooTallNate/NodObjC)


`NodObjC` exposes the Objective-C runtime to [Node.js][] in a high-level, easy
to use fashion. It uses the `BridgeSupport` files to dynamically generate an
API from an Objective-C "Framework", and uses `node-ffi` to dynamically interact
with the Objective-C runtime.

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

 * [JSCocoa][]
 * [PyObjC][]
 * [MacRuby][]
 * [And the others…][others]

So you can write entire Cocoa or iOS GUI applications entirely in Node.js
JavaScript! Applications are interpreted at runtime through the V8 engine,
rather than compiled to a machine exectuable. This has the advantage of being
able to tweak code without having to recompile; excellent for rapid prototyping
and development, or for those GUI applications where absolute speed is not a
requirement (i.e. _most_). So what are you waiting for? Get to coding!


Installation
------------

Install using `npm`, of course!

``` bash
$ npm install NodObjC
```

Or add it to the `"dependencies"` section of your _package.json_ file.


Hello World
-----------

``` javascript
var $ = require('NodObjC')

// First you import the "Foundation" framework
$.framework('Foundation')

// 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 (toString() ends up calling [string description])
console.log(string)
//   → Prints "Hello Objective-C World!"

pool('drain')
```

Be sure to check out the [full API docs][docs].


Introduction
------------

This module offers a bi-directional bridge between Node.js 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:

``` javascript
// In JavaScript, you invoke a function on an object like:
obj.func(arg)
```

Compared to:

``` javascript
// 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:

``` objective-c
[array insertObject: obj
       atIndex: 5]
```

The equivalent of the above message invocation in NodObjC syntax would be:

``` javascript
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:

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

There's a plethora of other Objective-C resources and tutorials out there.

You should definitely have Apple's official [Mac][MacDev] or [iOS][iOSDev] API
docs handy at all times.

Support / Getting Involved
---------------------------

If you're looking for support for developing with/for `NodObjC` you might want
to join the [mailing list][group], and check out the [#nodobjc][IRC] channel
in the Freenode IRC server.

Additional topics of discussion can be found on the [Wiki][] page.


[docs]: http://tootallnate.github.io/NodObjC
[group]: https://groups.google.com/d/forum/nodobjc
[Node.js]: http://nodejs.org
[JSCocoa]: http://inexdo.com/JSCocoa
[PyObjC]: http://pyobjc.sourceforge.net
[MacRuby]: http://macruby.org
[IRC]: http://webchat.freenode.net/?channels=nodobjc
[Wiki]: https://github.com/TooTallNate/NodObjC/wiki
[MacDev]: http://developer.apple.com/library/mac/navigation/
[iOSDev]: http://developer.apple.com/library/ios/navigation/
[ObjCWikipedia]: http://en.wikipedia.org/wiki/Objective-C
[others]: http://cocoadev.com/CocoaBridges

---
_Source: https://npm.io/package/NodObjC · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
