Search code examples
objective-cnsstringnsmutablearraynsarray

How to fetch data of NSString from array of structure hold by NSMutableArray in objective c?


I have one NSMutableArray tempArray = \[NSMutableArray array\]; which contains an array of structured objects with multiple data: brand_package_id , slide_master_id etc....

I want to sort out the tempArray according to slide_master_id's.
Please see given image and help me to sort this problem.

tempArray


Solution

  • Try using NSSortDescriptor:

      NSSortDescriptor *slideDescriptor = [[NSSortDescriptor alloc]
         initWithKey:@"slide_master_id" ascending:YES];
         NSArray *sortDescriptors = @[slideDescriptor];
     NSArray *sortedArray = [tempArray sortedArrayUsingDescriptors:sortDescriptors];