views:

166

answers:

4

I am trying to use an external Obj-C class in my MacRuby project, but I can't figure out how to import it. Specifically, I want to use ObjectiveResource inside a MacRuby 0.5 project (since ActiveResource doesn't work - yet).

I have gotten as far as the 'framework' command in MacRuby, but it only seems to apply to actual frameworks.

Questions: where should I install the objective-resource directory? how do I pull these classes inside my ruby code?

Thanks for any help!

A: 

Did you look at this example of creating an ObjC bundle?

sal
Yes, I have tried that, but I doesn't work at all for me. I did get a little closer by creating a bundle manually according to this (http://www.mail-archive.com/[email protected]/msg00940.html) example, but it is a very painful process and I haven't quite gotten it to work. I suppose the ObjectiveResource code (intended for iPhone apps) isn't all that suitable for this?
beno1604
What errors do you get when you try the bundle? Can you edit your post to include the error messages?
sal
+1  A: 

You can access the class directly using ClassName.new.

If you have a class named Utilities in your project and it has a method named greeting:, you would call it like so.

util = Utilities.new
puts util.greeting("Good morning")

There is no require or framework declarations required. Amazingly simple isn't it. I discovered this watching the Peepcode screencast on MacRuby.

Craig Williams
A: 

Also, if you are interested in calling Ruby code from Objective-c, here is an extract from the MacRuby mailing list:

Once the MacRuby runtime is initialized, you can access all your Objective-C objects from Ruby. For example, if you have an Objective-C class named Foo, you can do `Foo.new', etc.

Another possibility is to pass your Objective-C objects to a Ruby method by using -[NSObject performRubySelector:].

ruby: class Foo def test(o) o.something end end

objc: MyObject *o = [MyObject new]; // where o responds to -something MacRuby *runtime = [MacRuby sharedRuntime]; id foo_obj = [runtime evaluateString:@"new Foo"]; [foo_obj performRubySelector:@selector(test:) withArguments: o, NULL];

Check out the whole API here: http://www.macruby.org/trac/browser/MacRuby/trunk/include/ruby/objc.h

Thread: http://lists.macosforge.org/pipermail/macruby-devel/2010-April/004715.html

Matt Aimonetti
A: 

hi , I created a custom cocoa bundle. But when i try to load the bundle into MacRuby project,I get the following err

dyld: Library not loaded: audio_streamer.bundle Referenced from: /Users/sgopinath/workspace002/UplayaDesktopRadio/build/Debug/UplayaDesktopRadio.app/Contents/MacOS/UplayaDesktopRadio Reason: image not found

I created the bundle using the following command gcc audio_streamer.m -o audio_streamer.bundle -g -framework Foundation -dynamiclib - fobjc-gc -arch i386 -arch x86_64

I could load the bundle from macirb , but not from actual xcode project which is intended to use it.

Any suggestions

Thankyou sgopinath

Sowmya Gopinath