Sending messages to RubyCocoa from Obj-C with attributes | 07. Mai 2009 um 14:07 Uhr / Programming
I know that MacRuby is on the way and so on but I began Twittia in RubyCocoa, I wouldn't repeat that mistake, and I have to deal with it. The next time I'll write in Objective-C from the beginning.
Anyway, I found some nice classes which I needed for my project and they where written in Objective-C. I know how to send a message to a Objective-C object, you just replace the colons with underscores so
[myObject doSomethingWithObject:bar andOtherObject:baz];
would be in ruby
maObject.doSomethingWithObject_andOtherObject(bar, baz)
But what to do if you have to send a message to a RubyCocoa object?
Ok at the beginning it was easy, just reverse it, so
obj.doSomething
would just be
[obj doSomething];
and it worked great! But then I wanted to send some attributes like in the first example so I tried to send a object:
[obj takeThisObject:self]
and it also worked fine, but then I tried to send it a int which is a primitive type:
int i = 1; [obj takeThisInt:i]
and my programm would crash.
So after half a day I figured out that RubyCocoa takes only objects and crashes if you try to send it a primitive type. I Now first make a
[obj takeThisNumber:[NSNumber numberWithInt:i]];
and now it finally works.
Kommentare
Die Kommentare sind für diesen Eintrag geschlossen.




abonnieren.