4

I have a plist dictionary with several arrays where each have different number of items. These items are dictionaries too. So basically it looks like this:

  • Root dictionary
    • names array
    • places array
      • Item 0 dictionary
      • Item 1 dictionary
        • placeName string: "House"
        • description string: "My House"
        • height number: 10
      • Item 2 dictionary
      • ...
    • colors array
    • ...

I want to find the best way to change a value inside one of these arrays (placeName, description, height).

The plist is part of the resources, so I call it in like this:

[[NSMutableDictionary alloc] initFromName:@"mydefaults.plist"];

I've seen the setValue:forKey methods, but it looks like I'm heading into a mess. I don't think I should have to be setting the whole complete array if it's just one value.

So, which is the best way?

elcool
  • 6,041
  • 7
  • 29
  • 44

1 Answers1

6

How about something along the lines of

[[[plistDictionary objectForKey:@"places"] objectAtIndex:1] setValue:@"Another house" forKey:@"placeName"]

if the "internal" arrays and dictionaries are indeed mutable.

Jakob Borg
  • 23,685
  • 6
  • 47
  • 47
  • 1
    Yes; that you edit the dictionary in memory does not mean it gets saved to disk. You need a `[plistDictionary writeToFile:... atomically:...]` somwehere. – Jakob Borg Aug 28 '10 at 16:04