NSSortDescriptor - 根据一个特定子数组的计数对父 nsdictionnary 进行排序

NSSortDescriptor - sort parent nsdictionnary by count of one particular child array

我有一个主父 NSDictionnary,它包含多个对象,每个对象包含多个值。我想根据一个特定数组中的元素数量对整个 NSDictionnary 进行排序(字典中的每个对象都包含该数组)。

基本上,如果我的字典包含 3 个对象,每个对象都有一个名字、一个地址和一个包含他们拥有的所有朋友的名字的数组,我想根据每个朋友的数量对字典进行排序他们有,而不必为每个对象添加额外的元素(例如朋友的数量)。

我试过类似的东西:

descriptor = [NSSortDescriptor sortDescriptorWithKey:@"friends.count" ascending:NO];

但这行不通。我也看到了这个想法:

descriptor2 = [NSSortDescriptor sortDescriptorWithKey:@"@count" ascending:NO];

但这似乎只有在父数组只包含一个子数组的情况下才有效。

我怎样才能做到这一点?

您无法对字典进行排序。如果要对字典数组进行排序,请使用 friends.@count.