objective c - NSKeyedArchiver with pointers -
hi if want archive structure pointers in it, 2 different pointers point same place, after encoding-decoding point same place?
sorry bad english, , thx ahead answers , free time!
yes. if have 2 keys point same object, nskeyarchiver restore them keys pointing same object.
nsstring *one = @"1"; nsstring *two = @"2"; nsmutabledictionary *dict = [[[nsmutabledictionary alloc] initwithobjectsandkeys:one, @"one", two, @"two", one, @"three", nil] autorelease]; nslog(@"one=%d, two=%d, three=%d", [[dict objectforkey:@"one"] hash], [[dict objectforkey:@"two"] hash], [[dict objectforkey:@"three"] hash]); nsdata *data = [nskeyedarchiver archiveddatawithrootobject:dict]; dict = nil; // no tricks! dict = [nskeyedunarchiver unarchiveobjectwithdata:data]; nslog(@"one=%d, two=%d, three=%d", [[dict objectforkey:@"one"] hash], [[dict objectforkey:@"two"] hash], [[dict objectforkey:@"three"] hash]);
Comments
Post a Comment