• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to Handle Array of Dictionaries when Archiving/Unarchiving?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to Handle Array of Dictionaries when Archiving/Unarchiving?


  • Subject: Re: How to Handle Array of Dictionaries when Archiving/Unarchiving?
  • From: Alastair Houghton <email@hidden>
  • Date: Thu, 23 Jun 2016 14:00:31 +0100

On 23 Jun 2016, at 12:21, Dave <email@hidden> wrote:
>
> I have an Object that I Archive and Unarchive, e.g it conforms to the NSCopying and NSCoding Protocols. The Object in question contains NSArray and NSDictionary Object and I handle them like this:
>
> initWithCoder:
>
> myDictionary = [theCoder decodeObjectForKey:@"pLookUpDictionary "];
> self.pLookUpDictionary = [[NSMutableDictionary alloc] initWithDictionary:myDictionary copyItems:NO];

You don’t need to do that.  If you encode a mutable dictionary, you’ll get a mutable dictionary back.  The only time that doesn’t happen is with plists or NSUserDefaults; with NS[Keyed]Archiver, you get what you gave it.

> I now need to add another archivable property as so:
>
> @property (nonatomic,strong)	NSMutableDictionary<NSString*,NSArray<LTWClassX*>*>*		pLookUpDictionaryArray;
>
> How do I handle this in the above three methods? Specially do I need to walk the Array and do a mutableCopy on each of the Dictionaries in the Array?

No.  As long as your LTWClassX supports archiving, you can just tell the NSCoder to encode pLookUpDictionaryArray and it will handle the object graph for you.  It will even cope if your properties happen to refer to the same object more than once; it ensures that each object is stored only once, and that the resulting object graph is as it was when you saved it.

Kind regards,

Alastair.

--
http://alastairs-place.net


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >How to Handle Array of Dictionaries when Archiving/Unarchiving? (From: Dave <email@hidden>)

  • Prev by Date: How to Handle Array of Dictionaries when Archiving/Unarchiving?
  • Next by Date: NSArrayController - error inserting object at arranged object index N
  • Previous by thread: How to Handle Array of Dictionaries when Archiving/Unarchiving?
  • Next by thread: NSArrayController - error inserting object at arranged object index N
  • Index(es):
    • Date
    • Thread