Cocoa - Primitive Obj-C/Cocoa frontend
RForge.net

Cocoa

About Cocoa
SVN access
Download/Files
News
Check results

Cocoa is a small and crude package that allows you to send messages to Obj-C objects and classes and create references to objects, classes and selectors. For historical reasons it's called Cocoa (although Obj-C is strictly speaking not Cocoa).

It is interesting only for developers as it's only the first step in a complete Obj-C/R suite, but since some people seemed to be interested in this, I thought I share it here. Some (admittedly stupid) examples:

# Class sc = [NSString class]
> sc<-.MCall("NSString","class")
> sc
Obj-C class: NSString

# NSString *s = [NSString stringWithString:@"hello"]
> s <- .MCall("NSString","stringWithString:","hello")
> s
hello

# [s stringByAppendingString: @" World!")
> s2 <- .MCall(s, "stringByAppendingString:", " World!")
> s2
hello World!

# [s respondsToSelector: @selector(length)]
> .MCall(s, "respondsToSelector:", .MSelector("length"))
[1] TRUE

(the M in front of the calls was motivated by the .m extension of Obj-C code) and if you use Cocoa inside R.app you can do many stupid things like:

c<-.MCall("RController", "getRController")
.MCall(c, "toggleHistory:", c)
Currently only boolean, id and Class results are supported and only strings are automatically converted to NSString as arguments. Main work to be done now is the support for scalar types, especially Cocoa-native types like NSRange and so on. Anyone interested in this is welcome to enhance the code ... Comments are very welcome, too. But again, this is just a draft - no documentation, no guarantees ;).

As of version 0.1-1 it works with Apple's framework as well as with GNUstep.

As a side note, Duncan Temple-Lang has a similar package draft at http://www.omegahat.org/RObjectiveC. Combining both may be a good idea...