我需要一些帮助,根据每个对象 ISV 键对 NSDictionary 值的 NSArray 进行排序。
这是我迄今为止用于创建数组对象的代码,因此您可以更好地了解我正在尝试做什么。
NSArray *combinedKeysArray = [NSArray arrayWithObjects:@"HASM", @"ISL", @"ISV", nil];
valuesCombinedMutableArray = [NSMutableArray arrayWithObjects:[dict objectForKey:@"HASM"],
[dict objectForKey:@"ISL"],
[dict objectForKey:@"ISV"],
nil];
combinedDictionary = [NSDictionary dictionaryWithObjects:valuesCombinedMutableArray
forKeys:combinedKeysArray];
[unSortedrray addObject:combinedDictionary];
// how do I then sort unSortedArray by the string values in each object ISV key?
任何帮助将不胜感激。
最佳答案
这可以解决你的问题 如何对其中包含自定义对象的 NSMutableArray 进行排序? https://stackoverflow.com/a/805589/1294448
您可以使用 NSSortDescriptor 对 NSArays
进行排序
然后在 NSArray 中有一个名为 sortedArrayUsingDescriptors
的方法
或者 NSComparisonResult 有时也会有帮助 http://developer.apple.com/DOCUMENTATION/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/Reference/Reference.html#//apple_ref/doc/uid/20000138-BABCEEJD
关于ios - 基于单个对象键对 NSDictionary 进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18564867/