From: Wolfgang K. <kit...@ka...> - 2010-02-17 20:01:51
|
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? |