[MacRuby] #916: NSKeyedArchiver/Unarchiver generates multiple copies of the same object

MacRuby ruby-noreply at macosforge.org
Thu Dec 9 17:28:29 PST 2010


#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/>



More information about the macruby-tickets mailing list