2

I want to be sort NSMutableArray and its structure is something like that,

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";

... .. . . . ./

The array contains many objects, and those objects contain many dictionaries. I want to be able to arrange the above array in ascending order using the NSMutableDictionary key "Channel" ?

How can I sort the array?

0

2 Answers 2

3

Use NSSortDescriptor it will work

    NSSortDescriptor *aSortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"Channel" ascending:YES];
   [yourarrayobject sortUsingDescriptors:[NSArray arrayWithObject:aSortDescriptor]];
    [aSortDescriptor release];
Sign up to request clarification or add additional context in comments.

Comments

0

To sort your array of objects you:

  1. setup NSSortDescriptor - use names of your variables as keys to setup descriptor for sorting plus the selector to be executed on those keys
  2. get the array of descriptors using NSSortDescriptor that you've setup
  3. sort your array based on those descriptors

How to sort NSMutableArray using sortedArrayUsingDescriptors?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.