---
title: "return an array for section titles in table view"  
description: "return an array for section titles in table view"  
author: "Anonymous User"  
published: 2015-11-18  
updated: 2015-11-18  
canonical: https://www.mindstick.com/forum/33605/return-an-array-for-section-titles-in-table-view  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 1 minute  

---

# return an array for section titles in table view

I want to create an array for [section](https://yourviews.mindstick.com/view/297/reservation-for-economically-weaker-section) titles because section titles are the first letter for the items in the section.\
like contact list on [device](https://www.mindstick.com/blog/149/retriving-network-device-information-in-c-sharp), that displays in section [title](https://www.mindstick.com/articles/12860/how-to-get-financing-for-salvage-title-cars) like 'A' and after displaying [contacts](https://answers.mindstick.com/qa/50746/how-to-setup-your-contacts-on-your-iphone-7) which are started from [character](https://www.mindstick.com/articles/23551/an-investigate-distinctive-seafood-restaurant-for-your-image-stamp-character) 'A', and so on.\
Here is my code that I am using in my app:\

```
NSSortDescriptor *descriptorObj;descriptorObj = [[[NSSortDescriptor alloc] initWithKey:@"Name" ascending:YES] autorelease];NSArray *arrayObj;NSMutableArray *sectionTitlesArray = [tableDataSource valueForKey:@"Name"];NSArray *arrayUniq;arrayUniq = [[NSSet setWithArray:sectionTitlesArray] allObjects];arrayObj = [uniquearray arrayObjUsingSelector:@selector(caseInsensitiveCompare:)];
```

This code removes the [duplicate](https://www.mindstick.com/forum/160911/sql-query-to-find-duplicate-records-in-a-table-in-sql-server) titles and sorts the list alphabetically.\
Now I just need to [convert](https://www.mindstick.com/forum/2093/configurationmanager-appsettings-convert-n-to-n-why) the [strings](https://www.mindstick.com/forum/161912/explain-the-python-strings) in the array to the first letters only.\
Can [anyone tell me](https://www.mindstick.com/interview/23033/can-anyone-tell-me-about-hadoop-toolbox) the best way to do it?\
\

## Replies

### Reply by Tarun Kumar

You can use this code:

```
NSMutableSet *mutableSet = [NSMutableSet setWithCapacity:0];for(NSString*string in [dataSource valueForKey:@"Name"]){    [mutableSet addObject:[string substringToIndex:1]];}NSArray *sectionTitleArray = [[mutableSet allObjects]                              sortedArrayUsingSelector:@selector(                              caseInsensitiveCompare:)];
```


---

Original Source: https://www.mindstick.com/forum/33605/return-an-array-for-section-titles-in-table-view

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
