From: Eloy D. <elo...@gm...> - 2008-05-29 12:51:52
|
Hi Allison, Have you looked at /Developer/Examples/RubyCocoa/PDFKitViewer ? It has code for an outline view in MyPDFDocument.rb, it does use a NSMutableArray afaik, but it should be ducktypable by now. So ary.childAtIndex(index) could be written as arr[index]. So I wouldn't worry about that too much. Also if you send a plain ruby array through the bridge it will automatiucally be converted to a NSMutableArray. Cheers, Eloy On May 29, 2008, at 1:43 PM, Allison Newman wrote: > Hi Pim, > > Actually, I had already downloaded your project :-) You've done it > with bindings, I'm trying to do it as a plain-old data source. It's > my first Cocoa app, and others on the Cocoa dev list have suggested > that I should learn how to do this as a datasource first, to better > understand what bindings are doing. > > I have looked at the example OutlineView.rb that Tim Burks did that > shows a file system outline view done in RubyCocoa, but the only > difference that I can see between my code and his is that he only > uses Cocoa objects - indeed, I can see where he retrieves the list > of items in a directory ruby style, and then deliberately copies > the items out of the ruby array into an NSMutableArray, like this: > array = fileManager.directoryContentsAtPath(fp) > numChildren = array ? array.count : 0 > @children = > OSX::NSMutableArray.alloc.initWithCapacity(numChildren) > numChildren.times {|cnt| > item = > FileSystemItem.alloc.initWithPath_parent(array.objectAtIndex(cnt), > self) > @children.addObject(item) > } > That immediately made me suspect that something bad happens to ruby > arrays as they cross the bridge, to be returned by a Cocoa > callback. I guess I just wanted to confirm that this was indeed the > case. It basically forces me to remove ruby arrays from my models > and replace them with NSMutable arrays, which then implies that I > need to get rid of my YAML serialisation of data, and replace it > with Cocoa archiving code. It's a fair amout of work, and I just > wanted someone to confirm for me that this really is the problem, > before wasting a lot of time on something that wasn't necessary. I > guess this is what Tim was talking about when he said that you > can't really mix ruby libraries and Cocoa libraries (he used this as > his explanation for why he created nu in a talk at C4). > > Of course, if I'm right, this removes a lot of the joy from program > in ruby for the Mac. I'm starting to understand why Laurent felt it > necessary to start the MacRuby project. > > Thanks for the help anyway. > > Alli > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > Rubycocoa-talk mailing list > Rub...@li... > https://lists.sourceforge.net/lists/listinfo/rubycocoa-talk |