From: Allison N. <dem...@ma...> - 2010-02-17 21:35:18
|
Hmmm, not really. The best resource for explaining the bridge is Brian Marick's book, and the source code. Some of the answers I gave you yesterday were based on directly reading the source code for RubyCocoa. Sometimes I know what to do because I have seen how it was done in other people's RubyCocoa code. The example code in /Developer/ Examples/RubyCocoa is a very good resource. You can also try googling the method name using RubyCocoa syntax. For example, I learned about errors being returned when I was trying to work with QTKit. So I googled "QTMovie.movieWithFile_error" and found this: http://images.apple.com/server/macosx/docs/Podcast_Producer_Workflow_Tutorial.pdf which has this code in it: # Load the first movie. first_input_movie, error = OSX::QTMovie.movieWithFile_error(first_input_path) # Check to see if the first movie opened successfully. if first_input_movie == nil or error != nil $stderr.puts "could not load first movie" exit(1) end The last thing I can think of is to follow Brian's philosophy. If you are not sure how things work, try running a test case to see. For example, for your question about NSDictionary/Hash, the best thing to do is to try the ruby way and see if it works. If not, use the Cocoa way. I still find that the best thing to do is to read the source code, but then I am a very experienced C programmer, with a fair amount of experience in generating C/Ruby bindings, so it's fairly easy for me to do that. Of course, if you get stuck, that's what the mailing list is for.... Alli Le 17 févr. 10 à 21:01, Wolfgang Kittenberger a écrit : > Hi Allison, > > I like this answer! It explains, why I was not able the get that > "17 liner" working. > > To explain the background: I try to write the examples from the > Hillegass book (Cocoa Programming ..., 3. ed) in RubyCocoa. And I > have to admit, that my Objective-C and Cocoa knowledge is very > limited. > > In chapter 20 he writes a view to a PDF file and checks then if it > worked: > > ... > NSError *error; > BOOL successful = [data writeToFile: path > options:0 > error:&error]; > if (!successful) { > NSAlert *a = [NSAlert alertWithError:error]; > [a runModal]; > } > ... > > My naive approach to test the code for the error branch was to > generate the error by myself. This brought me to use ObjcPtr#assign > to set the errorpointer as described in my mail. > > When this did not work, I looked for descriptions for the ObjcPtr > class. But I did not find it. I had a look in the source of > "cls_objcptr.m", but it was double dutch for me. > > The I tried to generate the bridge-doc, which did not work. After > your hints I did this with the last but one versions of RubyCocoa > (0.13.2) and OSX(10.5.8). Then I was really disappointed, as I did > not find there anything about > my challenge. > > Now after your explanations I can see, that I was complete on the > wrong way. I did not understand, that NSAlert.alertWithError expects > not what I tried to construct (and failed). I even did not realize, > that there existst something like a Ruby NSError. > > I learned in the RubyCocoa book from Brian Marick, that there is a > Ruby NSRange, but I did not find anything about error handling. But > due to my long years programming experience, I am convinced that > checking errors is essential. > > So can you recommend some reading to get informations as gave it in > your mail, like where I can expect the RubyCocoa bridge to convert > Ruby objects to NS objects, and where I have to do it myself (e.g. > NSDictionary instead of a Ruby hash, or NSString.stringWithString > instead of a Ruby string)? Is the link "http://rubycocoa.sourceforge.net/HowDoesTheBridgeWork > " the only resource? > > Best regards > Wolfgang > > P.S.: > After your explanation of the usage of ObjcPtr#regard_as, I have had > a second look into the source code, but I would not be able to read > this out of the eleven pages without any explaining comments. So > there did you learn it? > > > > ------------------------------------------------------------------------------ > SOLARIS 10 is the OS for Data Centers - provides features such as > DTrace, > Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW > http://p.sf.net/sfu/solaris-dev2dev > _______________________________________________ > Rubycocoa-talk mailing list > Rub...@li... > https://lists.sourceforge.net/lists/listinfo/rubycocoa-talk |