Ios 对NSDictionary数组重新排序
如何按“ordinator”键对NSDictionary数组按此格式重新排序 我需要按“ordinator”键对它们重新排序,以便在表中显示它们。在其他包含对象的数组中,我使用sort来使用class属性进行排序。我可以做类似于此阵列的操作吗Ios 对NSDictionary数组重新排序,ios,sorting,cocoa-touch,nsarray,Ios,Sorting,Cocoa Touch,Nsarray,如何按“ordinator”键对NSDictionary数组按此格式重新排序 我需要按“ordinator”键对它们重新排序,以便在表中显示它们。在其他包含对象的数组中,我使用sort来使用class属性进行排序。我可以做类似于此阵列的操作吗 [ [ LogData = "17/05/2017 15:3:23"; LogDataInclusao = "17/05/2017 15:3:23"; Log
[
[
LogData = "17/05/2017 15:3:23";
LogDataInclusao = "17/05/2017 15:3:23";
LogNome = "Breno Bohm";
LogNomeInclusao = "Breno Bohm";
chave = I2017051715323LLNYB;
chaveNcm = 129;
date = "31/05/2017";
defaultPrice = "R$829,44";
discount1 = "0%";
discount2 = "0%";
discount3 = "0%";
discount4 = "0%";
discount5 = "0%";
price = "R$829,44";
productKey = 17392;
quantity = 1;
],
[
LogData = "17/05/2017 15:3:23";
LogDataInclusao = "17/05/2017 15:3:23";
LogNome = "Breno Bohm";
LogNomeInclusao = "Breno Bohm";
chave = I2017051715323LFGCG;
chaveNcm = 129;
date = "31/05/2017";
defaultPrice = "R$1.002,97";
discount1 = "0%";
discount2 = "0%";
discount3 = "0%";
discount4 = "0%";
discount5 = "0%";
price = "R$1.002,97";
productKey = 17391;
quantity = 1;
],
[
LogData = "17/05/2017 15:3:23";
LogDataInclusao = "17/05/2017 15:3:23";
LogNome = "Breno Bohm";
LogNomeInclusao = "Breno Bohm";
chave = I2017051715323KMPNY;
chaveNcm = 129;
date = "31/05/2017";
defaultPrice = "R$732,75";
discount1 = "0%";
discount2 = "0%";
discount3 = "0%";
discount4 = "0%";
discount5 = "0%";
price = "R$732,75";
productKey = 17394;
quantity = 1;
],
[
LogData = "17/05/2017 15:3:23";
LogDataInclusao = "17/05/2017 15:3:23";
LogNome = "Breno Bohm";
LogNomeInclusao = "Breno Bohm";
chave = I2017051715323JHRYJ;
chaveNcm = 747;
date = "31/05/2017";
defaultPrice = "R$270,44";
discount1 = "0%";
discount2 = "0%";
discount3 = "0%";
discount4 = "0%";
discount5 = "0%";
price = "R$270,44";
productKey = 17393;
quantity = 1;
]
]
是的,您可以按照相同的方式对字典数组进行排序,只需使用
下标
而不是属性
访问即可
带有键的排序数组包含字符串值
let sortedArray = yourArray.sorted { $0[yourKey] as? String ?? "" < $1[yourKey] as? String ?? "" }
让sortedArray=yourArray.sorted{$0[yourKey]作为?字符串??“<$1[yourKey]作为?字符串??”
带键的排序数组包含整数值
let sortedArray = yourArray.sorted { $0[yourKey] as? Int ?? 0 < $1[yourKey] as? Int ?? 0 }
让sortedArray=yourArray.sorted{$0[yourKey]as?Int??0<$1[yourKey]as?Int??0}
注意:您的
字典中没有排序符
键
,因此只需将您的键
替换为键
,即可对数组进行排序。是的,您可以按照相同的方式对字典数组进行排序,只需使用下标
而不是属性
访问即可
带有键的排序数组包含字符串值
let sortedArray = yourArray.sorted { $0[yourKey] as? String ?? "" < $1[yourKey] as? String ?? "" }
让sortedArray=yourArray.sorted{$0[yourKey]作为?字符串??“<$1[yourKey]作为?字符串??”
带键的排序数组包含整数值
let sortedArray = yourArray.sorted { $0[yourKey] as? Int ?? 0 < $1[yourKey] as? Int ?? 0 }
让sortedArray=yourArray.sorted{$0[yourKey]as?Int??0<$1[yourKey]as?Int??0}
注意:您的
字典中没有排序符
键
,因此只需将您的键
替换为键
,即可对数组进行排序。您可以在目标C中实现以下目标:
ordinatorDescriptor = [[NSSortDescriptor alloc] initWithKey:@"ordinator" ascending:YES];
sortDescriptors = [NSArray arrayWithObject:brandDescriptor];
sortedArray = [myArray sortedArrayUsingDescriptors:sortDescriptors];
您可以在目标C中实现这一点,如下所示:
ordinatorDescriptor = [[NSSortDescriptor alloc] initWithKey:@"ordinator" ascending:YES];
sortDescriptors = [NSArray arrayWithObject:brandDescriptor];
sortedArray = [myArray sortedArrayUsingDescriptors:sortDescriptors];
序号键在哪里?序号键在哪里?