I am working on converting a plain tableview to a sectioned tableview. I would like the section titles to be the first letter for the items in the section.
This is what I have so far in my titleForHeaderInSection method:
NSSortDescriptor *sortDescriptor;
sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"Name"
ascending:YES] autorelease];
NSArray *sortedArray;
NSMutableArray *commonNameArray = [tableDataSource valueForKey:@"Name"];
NSArray *uniquearray;
uniquearray = [[NSSet setWithArray:commonNameArray] allObjects];
sortedArray = [uniquearray sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
This code removes the duplicate titles and sorts the list alphabetically. Now I just need to convert the strings in the array to the first letters only. What is the best way to go about this?