Editing a multi-level .plist file

Discussion in 'iOS Programming' started by adriweb, Jan 14, 2011.

  1. adriweb, Jan 14, 2011
    Last edited: Jan 14, 2011

    macrumors newbie

    Oct 23, 2010

    I' ve been looking around, for quite a while now, for a way to edit a specific object in a multi-level .plist file. And I couldn't find anything anywhere...

    So, basically , here's the structure of the plist file :


    I thought of saving dictionaries as a an object (for each sublevel) but it didn't work really well (maybe I didn't do it correctly...) as it erased the other things ... :/

    And you can see on the image the value I want to change...

    Any ideas/advices appreciated !

    Thanks for the help !

  2. macrumors 68030


    Sep 2, 2008
    IMO, editing plists like this is no fun. Instead I write some code that builds the plist from some other kind of data structure like an array of structs and writes it out. I run this code on the Sim and move the plist file in the Finder to the Resources folder manually.

    This way editing the plist file is just a matter of editing some text, rather than opening up the plist editor, which is painful for complicated plist files, or making more than a few changes.

    There also are some plist editors that can be run from the command line or from a script that you might prefer.
  3. thread starter macrumors newbie

    Oct 23, 2010
    Oh, it's not that I'm building a program to help me edit .plist files, what I need to do is actually editing the .plist in my iOS app because my application is built around this database, and the object I want to edit is one of the value that I need for some feature I want to build :)

    Thanks for replying though !

    PS :

    this is the application I'm talking about :
  4. Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
    But not each sublevel is a dictionary, some are arrays.
  5. macrumors 68030


    Sep 2, 2008
    You want to modify the plist in response to user action or you want to edit to provide it as an update to the one that's in the app?

    In the first case you just need to use mutable containers. Replace or add or delete any of the content and write it out.

    In the second case my answer from earlier applies.
  6. macrumors regular

    Mar 30, 2008
    Uppsala, Sweden
    The plutil command is very handy for converting between plists and XML files.

    (Yes, I know this is not what the original poster asked for.)
  7. thread starter macrumors newbie

    Oct 23, 2010
    First Case, yep. It would be from a user filling a text field.

    So, how do I use mutable containers with what I already have ?

    (Actually, I already have some code to change the "most-inner" (as of the .plist structure) dictionary, but I don't know how to save that dictionary back into the sub-dictionary of the sub-array of the sub-dictionary of the sub-array ...)

    I mean, would I have to change the whole structure and not use .plist anymore ?
    Then I'd rather move to SQLite ;)

    Thanks for your answer.

    PS : the plist is mutable (and all dicts are)
  8. macrumors 68030


    Sep 2, 2008
    First, it's quite possible that sqlite or core data would be simpler for this. I guess it depends on the size and complexity of the data.

    If your containers are already mutable then its just a matter of using addObject, setObject:forkey:, replaceObjectAtIndex: and other methods for changing your data. Then you have to write out the plist.

Share This Page