如何正确排序 Plist?
好吧,我做了一个小游戏,在游戏结束时给我 3 个数据。
分数、硬币和等级。为此,我添加了排名。 (目前这是手动完成的,直到我弄清楚如何根据分数更改排名#)
所以,这是 Plist:
<?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>entry1</key>
<dict>
<key>rank</key>
<string>1</string>
<key>level</key>
<string>9</string>
<key>score</key>
<string>1999</string>
<key>coins</key>
<string>764</string>
</dict>
<key>entry2</key>
<dict>
<key>rank</key>
<string>2</string>
<key>level</key>
<string>8</string>
<key>score</key>
<string>1799</string>
<key>coins</key>
<string>375</string>
</dict>
<key>entry3</key>
<dict>
<key>rank</key>
<string>3</string>
<key>level</key>
<string>6</string>
<key>score</key>
<string>1599</string>
<key>coins</key>
<string>894</string>
</dict>
<key>entry4</key>
<dict>
<key>rank</key>
<string>4</string>
<key>level</key>
<string>3</string>
<key>score</key>
<string>799</string>
<key>coins</key>
<string>523</string>
</dict>
</dict>
</plist>
我希望能够按排名、硬币或级别对高分面板进行排序。
我尝试了很多方法来实现它,但没有任何方法能达到我想要的效果。
因此,如果有人能给我一些提示,我将非常感激。
提前致谢。
Well, I made a little game with give me at the end of the game, 3 datas.
Score, Coins, and Level. To this, I added the rank. (Which is manually done at the moment until I figure out how to change the rank # depending on the score)
So, here is the Plist:
<?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>entry1</key>
<dict>
<key>rank</key>
<string>1</string>
<key>level</key>
<string>9</string>
<key>score</key>
<string>1999</string>
<key>coins</key>
<string>764</string>
</dict>
<key>entry2</key>
<dict>
<key>rank</key>
<string>2</string>
<key>level</key>
<string>8</string>
<key>score</key>
<string>1799</string>
<key>coins</key>
<string>375</string>
</dict>
<key>entry3</key>
<dict>
<key>rank</key>
<string>3</string>
<key>level</key>
<string>6</string>
<key>score</key>
<string>1599</string>
<key>coins</key>
<string>894</string>
</dict>
<key>entry4</key>
<dict>
<key>rank</key>
<string>4</string>
<key>level</key>
<string>3</string>
<key>score</key>
<string>799</string>
<key>coins</key>
<string>523</string>
</dict>
</dict>
</plist>
I would like to be able to sort the highscore panels by rank, or coins, or level.
I've tried many things to achieve it but nothing does what I want.
So if anyone can give me some tips, I'll be very grateful.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
属性列表是存储数据的格式。要对其进行排序,您应该:
使用适当的结构很重要。属性列表支持两种容器对象:数组和字典。数组是有序列表;字典是键/值对的无序列表。看起来您现在正在使用一本字典,其中的键表示顺序。您应该更改存储方案以使用数组。然后您可以根据分数对数组进行排序并将其写入文件。
The property list is the format of the data in storage. To sort it, you should:
Using an appropriate structure is important. Property lists support two kinds of container objects: arrays and dictionaries. Arrays are ordered lists; dictionaries are unordered lists of key/value pairs. It looks like you're using a dictionary right now, with keys that indicate order. You should change your storage scheme to use an array instead. Then you can just sort the array according to score and write it out to a file.