标签:
面试总结(四)实现有序字典
实现方法
这里只说大概的两张方法的实现
方法一
1 NSArray *keys = [dict allKeys];
2 NSArray *sortedArray = [keys sortedArrayUsingComparator:^NSComparisonResult(idobj1, id obj2) {
3 return [obj1 compare:obj2 options:NSNumericSearch];
4 }];
5 for (NSString *categoryId in sortedArray) {
6 ……
7 NSLog(@"[dict objectForKey:categoryId] === %@",[dictobjectForKey:categoryId]);
8 }
方法二:
1 NSString *filePath = [[NSBundle mainBundle]pathForResource:@"students" ofType:@"plist"]; 2 NSDictionary *stuDic = [NSDictionary dictionaryWithContentsOfFile:filePath]; 3 self.studentIndexArray = [NSMutableArray arrayWithCapacity:1]; 4 NSArray *arr = [[stuDic allKeys] sortedArrayUsingSelector:@selector(compare:)];
标签:
原文地址:http://www.cnblogs.com/stronger-ios-lcx/p/5634959.html