From: Stephyn B. <ste...@gm...> - 2008-07-26 06:06:50
|
Hi all, I have a very simple app I'm trying to write to spike out some key portions of an app I'm planning to write. The application is not document based but I do want to be able to save and load the object model. The "preferred" form is YAML with import/ export using XML. The application is dirt simple. Just an array of Friends visible through a NSTable and the Friend objects themselves which can be edited. I can successfully save the @friends array as a YAML file (saveFriends)...but I get thrown into the debugger every time I tried to load a YAML file (openFriends). I've narrowed it down to YAML::load as the line that crashes (I can read the file, and print out the contents to NSLog just fine). Any ideas? If you're curious and want to kick the tires, you can download the project at http://homepage.mac.com/stephyn/Friends.zip Thanks a bunch. Cheers, Steve ---Friend.rb require 'osx/cocoa' class Friend < OSX::NSObject include OSX kvc_accessor :name, :email, :cell def init if super_init @name = "New Friend" @email = "New Email" @cell = "New Cell" self end end end ---AppController.rb require 'osx/cocoa' require 'yaml' class AppController < OSX::NSObject include OSX kvc_accessor :friends def init if super_init @friends = NSMutableArray.array self end end def saveFriends( sender) friends = @friends.to_ruby panel = NSSavePanel.savePanel if panel.runModal == NSFileHandlingPanelOKButton filename = panel.filename.to_ruby else return end File.open( filename, "w") { |file| file.puts friends.to_yaml} end ib_action :saveFriends def openFriends( sender) panel = NSOpenPanel.openPanel if panel.runModal == NSFileHandlingPanelOKButton filename = panel.filename.to_ruby else return end @friends = YAML::load( File.open( filename, "r")) end ib_action :openFriends end |