iphone - 排序 NSMutableArray?

  显示原文与译文双语对照的内容
0 0

我想把NSMutableArray分类它的结构就像这样

Object1:NSMutableDictionary


 Affiliation = 2165;
 CallLetters = abc;
 Channel ="2.1";

 ChannelLocation ="";
 ChannelSchedules = (
 );
 DisplayName = abc;
 DvbTriplets = (
 );
 FullName ="bc";
 IconAvailable = 1;
 Order = 1;
 ParentNetworkId = 2;
 ServiceType = Digital;
 SourceAttributeTypes = 
 HD

 SourceId = 11222;
 SourceType = Broadcast;
 TiVoSupported = 1;
 Type ="24-Hours";

Object2:NSMutableDictionary


 Affiliation = 1209;
 CallLetters ="xyz";
 Chann?el ="4.1";

 ChannelLocation ="";
 ChannelSchedules = (
 );
 DisplayName ="xyz";
 DvbTriplets = (
 );
 FullName ="xyz";
 IconAvailable = 1;
 Order = 2;
 ParentNetworkId = 5;
 ServiceType = Digital;
 SourceAttributeTypes = HD

 SourceId = 111
 SourceType = Broadcast;
 TiVoSupported = 1;
 Type ="24-Hours";
 VirtualChannelNumber ="4.1";

。。/

array 包含许多对象,这些对象包含许多字典。 我希望能够使用NSMutableDictionary键"频道"以升序排列上面的array?

如何对 array 进行排序?

时间: 原作者:

0 0

使用NSSortDescriptor它将工作


 NSSortDescriptor *aSortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"Channel" ascending:YES];
 [yourarrayobject sortUsingDescriptors:[NSArray arrayWithObject:aSortDescriptor]];
 [aSortDescriptor release];

原作者:
0 0

若要对你的array 对象进行排序:

  1. 设置 NSSortDescriptor - 使用变量名称作为设置描述符的键和要在这些键上执行的选择器
  2. 使用已经设置的NSSortDescriptor获取描述符的array
  3. 根据这些描述符对 array 进行排序

如何使用sortedArrayUsingDescriptors排序 NSMutableArray

原作者:
...