2011-04-26 44 views
1

是否可以按照字母順序排列插入plist的數據?如何?如果不是如何使用數組或其他方法點?如何在plist中對數據進行排序?

感謝advace

+0

歡迎StackOverflow上。確保您在發佈問題之前閱讀常見問題解答。另外,在發佈問題之前,嘗試使用搜索功能找到答案。在這個問題上已經發布了很多問題和解決方案。 – Till 2011-04-26 19:30:25

回答

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]); 
} 
相關問題