[MacRuby-devel] [MacRuby] #122: error in objects initialized with an options hash and KVO (maybe a caching issue in dispatcher)

MacRuby ruby-noreply at macosforge.org
Tue Sep 2 20:42:53 PDT 2008


#122: error in objects initialized with an options hash and KVO (maybe a caching
issue in dispatcher)
--------------------------------+-------------------------------------------
 Reporter:  rich at infoether.com  |       Owner:  lsansonetti at apple.com
     Type:  defect              |      Status:  new                  
 Priority:  blocker             |   Milestone:                       
Component:  MacRuby             |    Keywords:                       
--------------------------------+-------------------------------------------
 The following code should work:

 {{{
 framework 'cocoa'
 class Foo
   attr_accessor :subject, :key, :another_key
   def initialize(subject, options={})
     @subject = subject
     @key = options[:key]
     @another_key = options[:another_key]
   end
 end


 def objects
   [Foo.new("test", :key => 'key', :another_key => 'another_key'),
 Foo.new("test2", :key => 'key2', :another_key => 'another_key2')]
 end

 controller = NSArrayController.alloc.init
 controller.addObjects(objects)
 controller.setAvoidsEmptySelection(true)
 controller.setPreservesSelection(false)
 controller.setSelectsInsertedObjects(false)
 controller.setAutomaticallyRearrangesObjects(true)
 controller.setSortDescriptors([NSSortDescriptor.alloc.initWithKey("subject",
 ascending: true)])
 }}}

 If instead you place a single item it works:

 {{{
 def objects
   [Foo.new("test", :key => 'key', :another_key => 'another_key')]
 end
 }}}

 Or if you make the second item have a different set of keys...

 {{{
 def objects
   [Foo.new("test", :key => 'key', :another_key => 'another_key'),
 Foo.new("test2", :another_key => 'another_key')]
 end
 }}}

 This it works again...

-- 
Ticket URL: <http://www.macruby.org/trac/ticket/122>
MacRuby <http://macruby.org/>



More information about the MacRuby-devel mailing list