---
title: "How to sort object with property in NSArray."  
description: "How to sort object with property in NSArray."  
author: "Norman Reedus"  
published: 2015-02-12  
updated: 2015-02-12  
canonical: https://www.mindstick.com/forum/12956/how-to-sort-object-with-property-in-nsarray  
category: "iphone"  
tags: ["iphone", "ios"]  
reading_time: 1 minute  

---

# How to sort object with property in NSArray.

How to sort object with [property](https://www.mindstick.com/blog/205/property-notification-in-c-sharp) in NSArray.

## Replies

### Reply by Elena Glibart

```
@interface Person : NSObject@property (nonatomic, retain) NSString *Name;@property (nonatomic, retain) NSString *City;@property (nonatomic, retain) NSString *Country;@end   Person *p1=[Person alloc]init];p1.Name=@“Anil”;p1.City=@“Uttarpradesh”;p1.Country=@“India”; Person *p2=[Person alloc]init];p2.Name=@“Rakesh”;p2.City=@“Uttarpradesh”;p2.Country=@“India”; Person *p3=[Person alloc]init];p3.Name=@“Mayank”;p3.City=@“Uttarpradesh”;p3.Country=@“India”;  NSArray*UnSortedArray=[NSArray arrayWithObjects:p1,p2,p3, nil];    NSArray *sortedArray=nil;   Bool  isUseCaseInsensitiveCompare=false;    @try    {    NSSortDescriptor*valueDescriptor = nil;   
if(isUseCaseInsensitiveCompare)    { valueDescriptor=[[NSSortDescriptor alloc] initWithKey:@”Name” ascending:YES
selector:@selector(caseInsensitiveCompare:)];    }    else{       valueDescriptor=[[NSSortDescriptor alloc] initWithKey:@”Name” ascending:YES];      }    NSMutableArray * descriptors= [NSMutableArray arrayWithObject:valueDescriptor];    sortedArray =[UnSortedArray sortedArrayUsingDescriptors:descriptors ];    }    @catch (NSException*ex) {       
NSLog(@"%@",ex.reason);    }
```


---

Original Source: https://www.mindstick.com/forum/12956/how-to-sort-object-with-property-in-nsarray

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
