---
title: "Sorting mutable array in ascending order in Objective-C"  
description: "Sorting mutable array in ascending order in Objective-C"  
author: "David Miller"  
published: 2015-12-07  
updated: 2015-12-08  
canonical: https://www.mindstick.com/forum/33695/sorting-mutable-array-in-ascending-order-in-objective-c  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 1 minute  

---

# Sorting mutable array in ascending order in Objective-C

I have created a **studentDB** table in a [SQLite database](https://www.mindstick.com/articles/1554/crud-operation-in-asp-dot-net-using-sqlite-database) and storing the [data](https://www.mindstick.com/articles/13050/salesforce-aiming-to-dominate-predictive-analytics-with-data-science) of studentDB in an **NSMutableArray**.\
I have created [attributes](https://www.mindstick.com/articles/13105/2-attributes-that-make-your-odoo-ecommerce-theme-productive-and-engaging) in our **studentDB** main **attributs** are as follows: **Student_Name, Registration_No, Date_of_Join.**

[Now](https://yourviews.mindstick.com/view/81402/it-s-liberals-vs-progressives-in-us-politics-now), I want to sort this mutable [array](https://www.mindstick.com/articles/335/jagged-array-in-c-sharp-dot-net) according to Student_Name in **ascending** [order](https://www.mindstick.com/articles/12276/how-timely-order-deliveries-can-improve-customer-experience) in a **[Table View](https://www.mindstick.com/forum/33654/send-table-view-cell-value-on-button-action-in-ios)**.

So, how can I do this. any help would be appreciated.

## Replies

### Reply by Tarun Kumar

For sorting arrays use **NSSortDescriptor**'s method **sortUsingDescriptors:sortDescriptors** to sort a mutable array.\
for Ex:

```
NSSortDescriptor *descriptor = [[NSSortDescriptor alloc]                                initWithKey:@"Date_Of_Join" ascending:YES];NSArray *sortDescriptors = [NSArray arrayWithObject:descriptor];[array sortUsingDescriptors:sortDescriptors];[descriptor release];
```

We can sort using different methods:\
- (NSArray *)sortedArrayUsingFunction:(NSInteger (*)(id, id, void *))comparator context:(void *)context\
- (NSArray *)sortedArrayUsingSelector:(SEL)comparator\
- (NSArray *)sortedArrayUsingComparator:(NSComparator)cmptr\
- (NSArray *)sortedArrayWithOptions:(NSSortOptions)opts usingComparator:(NSComparator)cmptr\


---

Original Source: https://www.mindstick.com/forum/33695/sorting-mutable-array-in-ascending-order-in-objective-c

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
