如何在plist中对数据进行排序?

时间:2011-04-26 19:07:50

标签: iphone

是否可以按字母顺序对插入plist中的数据进行排序?如何?如果不是如何使用数组或任何其他方法点?它

先谢谢

1 个答案:

答案 0 :(得分:1)

// read the file into a dictionary
NSString *path = [[NSBundle mainBundle] pathForResource:@"yourfile" ofType:@"plist"];
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
// sort it
NSArray *sortedArray = [[myDict allKeys] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
// iterate and print results
for(NSString *key in sortedArray) {
    NSLog(@"key=%@,value=%@", key, [dict objectForKey:key]);
}
相关问题