gpt4 book ai didi

iOS NSArray 排序

转载 作者:行者123 更新时间:2023-11-29 10:54:30 24 4
gpt4 key购买 nike

我有一个嵌套数组,想通过内部数组中存在的键对其进行排序。下面给出的是我的数组,我想使用 NSSortDescriptor 或其他方式对其进行排序。

fares(
{
pid = 1;
type1 = (
{
color = "red";
size = "big";
properties = (
{
mod = "auto";
payment = "EMI";
moresegs = (
{
id = 141;
name = "abcd";
duration = "1 year"
})
})
});
type2 = (
{
color = "green";
size = "small";
properties = (
{
mod = "auto";
payment = "EMI";
moresegs = (
{
id = 141;
name = "abcd";
duration = "1 year"
})
})
})
}

{
pid = 1;
type1 = (
{
color = "red";
size = "big";
properties = (
{
mod = "auto";
payment = "EMI";
moresegs = (
{
id = 141;
name = "abcd";
duration = "1 year"
})
})
});
type2 = (
{
color = "green";
size = "big";
properties = (
{
mod = "auto";
payment = "EMI";
moresegs = (
{
id = 141;
name = "abcd";
duration = "1 year"
})
})
})
})

如何使用键 "type2->properties->payment" 对上述数组进行排序?

--------更新------------

我修改了数组并使用 NSSortDescriptor 解决了我的问题

最佳答案

试试这个:

NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"type1.size" ascending:YES];
NSArray *finalArray = [self.firstArray sortedArrayUsingDescriptors:[NSArray arrayWithObjects:descriptor,nil]];

关于iOS NSArray 排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19020429/

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