Search code examples
iphonecocoasortingplistnsdictionary

Is there an easy way of sorting a plist (array of dictionaries) by key value?


I need to reorder a plist (an array of dictonaries) by Key value.

In this example content I'd like to order by the value for the key Name (Matt, Joe):

<dict>
    <key>Name</key>
    <string>Matt</string>
    <key>Details</key>
    <string>Me</string>
</dict>
<dict>
    <key>Name</key>
    <string>Joe</string>
    <key>Details</key>
    <string>You</string>
</dict>

Is there an easy way? I don't want to do it in code each time the app is run, I just want to do it to the data file.

Any ideas?

Happy to use any tool to get this done: ninja parameters for sort on the command line, a plist editor, text editor or whatever.


Solution

  • I ended up writing a five line PHP script to reorder them. I guess I still have a lot of Cocoa to learn before I can do something that quickly and comfortably with it.

    Thanks for your answers.