I have a plist like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>highscores</key>
<array>
<dict>
<key>highscoreInSeconds</key>
<string>9</string>
<key>levelName</key>
<string>1</string>
<key>name</key>
<string>Black</string>
</dict>
<dict>
<key>highscoreInSeconds</key>
<string>12</string>
<key>levelName</key>
<string>1</string>
<key>name</key>
<string>Black</string>
</dict>
</array>
</dict>
</plist>
Now I want to sort this by the highscoreInSeconds
.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *plistDirectory = [paths objectAtIndex:0];
NSString* fullPath = [plistDirectory stringByAppendingPathComponent:@"data.plist"];
NSMutableDictionary* pData = [[NSMutableDictionary alloc] initWithContentsOfFile:fullPath];
NSMutableArray* highscores = [pData valueForKey:@"highscores"];
How can I sort this now?
Thank you very much!
:)
Have a nice day.
PS: It should look like this at the end:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>highscores</key>
<array>
<dict>
<key>highscoreInSeconds</key>
<string>12</string>
<key>levelName</key>
<string>1</string>
<key>name</key>
<string>Black</string>
</dict>
<dict>
<key>highscoreInSeconds</key>
<string>9</string>
<key>levelName</key>
<string>1</string>
<key>name</key>
<string>Black</string>
</dict>
</array>
</dict>
</plist>
You don't need to say me how to write a plist i knew that.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…