0

I read the following link About sorting NSArray

But I am struggling to convert this to my use case where I need to manually sort based on values that are inside an NSDictionary inside an NSArray.

I tried to google search for Sort using NSDictionary inside NSArray but got no good hits. Can someone please point me in the right direction?

djromero
  • 19,551
  • 4
  • 71
  • 68
Matt Douhan
  • 2,053
  • 1
  • 21
  • 40
  • Do you want to sort a `NSMutableArray` or `NSArray`? What did you try and what was the result? – Willeke Jan 13 '18 at 11:02
  • It’s a NSMutableArray that I want sort based on a name that is held in a Dictionary inside the array, I didn’t try anything cause I cannot find any pointers that explains how – Matt Douhan Jan 13 '18 at 14:13
  • [Sorting Arrays](https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Collections/Articles/Arrays.html#//apple_ref/doc/uid/20000132-SW5) – Willeke Jan 13 '18 at 16:16

1 Answers1

1

This is very easy to sort a NSArray of Dictionary

Use

 NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:@"Your key" ascending:YES];
 NSArray *sortedArray = [yourUnsortedArray sortedArrayUsingDescriptors:@[sort]];

It will work.

Just change the key name and array name according to you.

djromero
  • 19,551
  • 4
  • 71
  • 68
Parvendra Singh
  • 965
  • 7
  • 19