Save NSDictionary to plist

Ashley Staggs picture Ashley Staggs · Jun 10, 2011 · Viewed 35.1k times · Source

I am using the code found in this post: Mulitple Arrays From Plist, with the same plist formatting.

This works successfully, however I do not know how to save the created arrays back into a plist, in the same format.

How would I achieve this?

EDIT: It is not so much the saving that I need, but the forming of the data to save.
The plist is an array of dictionaries with strings and their corresponding keys. All the strings with a certain key are put into an array of their own.

How would I put that array back into the correct positions in the array of dictionaries, ready to save?

Answer

John Calsbeek picture John Calsbeek · Jun 10, 2011

Here's the simplest way:

NSDictionary* dict = ...;
[dict writeToFile:@"..." atomically:YES];

See the documentation for -writeToFile:atomically:.