Saturday 15 May 2010

iphone - NSCoding and ARC -


I want to store my custom object. The class sees a dictionary whose values ​​are examples of Classbie.

Everything is good class A's input with coder, and _diker is declared as strong , but after init return and I call callMeAfterInit , _dictionary is empty (not empty, a valid empty dictionary).

It should be simple, but I have not done a lot of collection, so I'm missing something fundamental. What could be the reason to clear the dictionary after return returns?

Here is the required code:

  @interface ClassA: NSObject & lt; NSCoding & gt; @protecti (strong, non-standard) NSMutableDictionary * dictionary; @end @implementation ClassA - (Zero) Encoded Password: (Encoder *) Encoder {[Encoder encoded object: self.dictionary forKey: @ "dictionary"]; } - (id) initWithCoder: (encoder *) decoder {self = [super init]; If (self) {_dictionary = [decoder DecodeObjectForKey: @ "dictionary"]; // Breakpoint here and I can inspect a good dictionary; healthy return to classy values}; } - (zero) callMeAfterInit {NSLog (@ "% @", self.dictionary); // Log output shows an empty dictionary here (valid, but with 0 pair)} @ and @ interface class B: NSObject & lt; Nscding & gt; @property (strong, non-nautical) nsnm * number; @ Property (strong, non-fixed) NSArray * array; @end @ Implementation Classbie - (empty) encoded codec: (encoder *) encoder {[encoder encoded object: self number fork: @ "number"]; [Encoder encoded object: self. For Hey: @ "Array"]; } - (id) initWithCoder: (encoder *) decoder {self = [super init]; If (self) {_number = [decoder DecodeObjectForKey: @ "number"]; _arre = [decoder decodeObjectForKey: @ "array"]; } Healthy return; } @end    

You do not show the code that calls callMeAfterInit < / Code>, then this is an estimate.

No more than you are, you are not talking to the same example as ClassA . Do you call [[ClassA alloc] init]; from somewhere?

No comments:

Post a Comment