PDA

View Full Version : Editing a multi-level .plist file




adriweb
Jan 14, 2011, 03:46 PM
Hello,

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 :

http://i.imgur.com/9aXEa.jpg


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 !


Adrien



PhoneyDeveloper
Jan 14, 2011, 06:05 PM
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.

adriweb
Jan 14, 2011, 06:18 PM
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 :
http://itunes.apple.com/us/app/isen-colles-n1a/id412495736?mt=8&ls=1

dejo
Jan 14, 2011, 06:41 PM
I thought of saving dictionaries as a an object (for each sublevel)
But not each sublevel is a dictionary, some are arrays.

PhoneyDeveloper
Jan 14, 2011, 07:24 PM
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.

bredell
Jan 14, 2011, 09:25 PM
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.

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.)

adriweb
Jan 15, 2011, 12:35 AM
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.

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)

PhoneyDeveloper
Jan 15, 2011, 11:39 AM
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.