gpt4 book ai didi

ios - 根据单个对象键对 NSDictionary 进行排序

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:11:17 25 4
gpt4 key购买 nike

我需要一些帮助来根据每个对象 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com