From: Allison N. <dem...@ma...> - 2008-05-29 11:43:44
|
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 |