Projects
Home     Blog     Install     New Ticket     View Tickets     Browse Source

Ticket #122 (closed defect: fixed)

Opened 3 months ago

Last modified 3 months ago

error in objects initialized with an options hash and KVO (maybe a caching issue in dispatcher)

Reported by: rich@… Owned by: lsansonetti@…
Priority: blocker Milestone: MacRuby 0.3
Component: MacRuby Keywords:
Cc:

Description

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...

Change History

Changed 3 months ago by lsansonetti@…

  • milestone set to MacRuby 0.3

Changed 3 months ago by lsansonetti@…

It's because objects()[0] is not an instance of Foo, but Foo itself (the class).

$ cat /tmp/t.rb 
class Foo
  def initialize(subject, options={})
  end
end

p [Foo.new(1, :x => 42, :y => 43), Foo.new(2, :x => 42, :y => 43)]
$ ./miniruby /tmp/t.rb 
[Foo, #<Foo:0x1077480>]
$ 

Looks definitely like a bad bug in the core :-)

Changed 3 months ago by lsansonetti@…

  • status changed from new to closed
  • resolution set to fixed

Fixed in r551/trunk.

Note: See TracTickets for help on using tickets.