[MacRuby] #916: NSKeyedArchiver/Unarchiver generates multiple copies of the same object
#916: NSKeyedArchiver/Unarchiver generates multiple copies of the same object ---------------------------------+------------------------------------------ Reporter: mred@… | Owner: lsansonetti@… Type: defect | Status: new Priority: major | Milestone: Component: MacRuby | Keywords: ---------------------------------+------------------------------------------ {{{ $ cat test.rb class A attr_accessor :a def initWithCoder coder @a = coder.decodeObjectForKey 'a' self end def encodeWithCoder coder coder.encodeObject @a, forKey:'a' end end a = A.new b = A.new a b.a = a puts(a == b.a) data = NSKeyedArchiver.archivedDataWithRootObject a a = NSKeyedUnarchiver.unarchiveObjectWithData data puts(a == b.a) $ macruby test.rb true false }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/916> MacRuby <http://macruby.org/>
#916: NSKeyedArchiver/Unarchiver generates multiple copies of the same object ---------------------------------+------------------------------------------ Reporter: mred@… | Owner: lsansonetti@… Type: defect | Status: new Priority: major | Milestone: Component: MacRuby | Keywords: ---------------------------------+------------------------------------------ Comment(by mred@…): Sorry, this doesn't work because is shouldn't work. I'm having problems with duplicate objects using NSKeyedArchiver/Unarchiver, but this doesn't demonstrate the problem. I'll try to generate a valid example of the problem and resubmit. -- Ticket URL: <http://www.macruby.org/trac/ticket/916#comment:1> MacRuby <http://macruby.org/>
#916: NSKeyedArchiver/Unarchiver generates multiple copies of the same object ---------------------------------+------------------------------------------ Reporter: mred@… | Owner: lsansonetti@… Type: defect | Status: new Priority: major | Milestone: Component: MacRuby | Keywords: ---------------------------------+------------------------------------------ Comment(by mred@…): Ok, I've provided an example as an attachment that I believe demonstrates the problem. It appears that the common identity of objects is missed when objects are used as keys in a Hash. Encoding the hash's keys as an array seems to work however. -- Ticket URL: <http://www.macruby.org/trac/ticket/916#comment:2> MacRuby <http://macruby.org/>
#916: NSKeyedArchiver/Unarchiver generates multiple copies of the same object ---------------------------------+------------------------------------------ Reporter: mred@… | Owner: lsansonetti@… Type: defect | Status: closed Priority: major | Milestone: Component: MacRuby | Resolution: invalid Keywords: | ---------------------------------+------------------------------------------ Changes (by lsansonetti@…): * status: new => closed * resolution: => invalid Old description:
{{{ $ cat test.rb class A attr_accessor :a
def initWithCoder coder @a = coder.decodeObjectForKey 'a' self end
def encodeWithCoder coder coder.encodeObject @a, forKey:'a' end end
a = A.new b = A.new
a b.a = a
puts(a == b.a)
data = NSKeyedArchiver.archivedDataWithRootObject a a = NSKeyedUnarchiver.unarchiveObjectWithData data
puts(a == b.a)
$ macruby test.rb true false }}}
New description: {{{ $ cat test.rb class A attr_accessor :a def initWithCoder coder @a = coder.decodeObjectForKey 'a' self end def encodeWithCoder coder coder.encodeObject @a, forKey:'a' end end a = A.new b = A.new a b.a = a puts(a == b.a) data = NSKeyedArchiver.archivedDataWithRootObject a a = NSKeyedUnarchiver.unarchiveObjectWithData data puts(a == b.a) $ macruby test.rb true false }}} -- Comment: That seems perfectly normal: the unarchiver will return a new instance every time. Messaging #== will return false as the two objects are not the same instance. You will have to overwrite the method. This will behave the same in Objective-C, as -isEqual: also does pointers comparison. -- Ticket URL: <http://www.macruby.org/trac/ticket/916#comment:3> MacRuby <http://macruby.org/>
participants (1)
-
MacRuby