首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >排序NSMutableArray?

排序NSMutableArray?
EN

Stack Overflow用户
提问于 2011-10-13 18:12:02
回答 2查看 4.8K关注 0票数 2

我想要sort NSMutableArray,它的结构是这样的,

Object1:NSMutableDictionary

代码语言:javascript
复制
   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

代码语言:javascript
复制
   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";

... ..。。。./

该数组包含许多对象,而这些对象包含许多字典。我希望能够使用通道键“NSMutableDictionary”按升序排列上面的数组?

如何对数组进行排序?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-10-13 18:21:28

使用NSSortDescriptor就可以了

代码语言:javascript
复制
    NSSortDescriptor *aSortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"Channel" ascending:YES];
   [yourarrayobject sortUsingDescriptors:[NSArray arrayWithObject:aSortDescriptor]];
    [aSortDescriptor release];
票数 3
EN

Stack Overflow用户

发布于 2011-10-13 18:48:24

要对对象数组进行排序,请执行以下操作:

  1. setup NSSortDescriptor -使用变量的名称作为键设置描述符以进行排序,外加对这些键执行的选择器
  2. 使用已设置的NSSortDescriptor获取描述符数组
  3. 根据这些描述符对数组进行排序

How to sort NSMutableArray using sortedArrayUsingDescriptors?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7752563

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档