i'm wondering on how to sort Chinese character into "#" instead of A-Z.
any comments are greatly appreciated.
-(NSArray *)partitionObjects:(NSArray *)array collationStringSelector:(SEL)selector
{
self.collation = [UILocalizedIndexedCollation currentCollation];
NSInteger sectionCount = [[self.collation sectionTitles] count];//section count is take from sectionTitles and not sectionIndexTitles
NSMutableArray *unsortedSections = [NSMutableArray arrayWithCapacity:sectionCount];
//create an array to hold the data for each section
for(int i = 0; i < sectionCount; i++)
{
[unsortedSections addObject:[NSMutableArray array]];
}
//put each object into a section
for (id object in array)
{
NSInteger index = [self.collation sectionForObject:object collationStringSelector:selector];
[[unsortedSections objectAtIndex:index] addObject:object];
}
NSMutableArray *sections = [NSMutableArray arrayWithCapacity:sectionCount];
//sort each section
for (NSMutableArray *section in unsortedSections)
{
[sections addObject:[self.collation sortedArrayFromArray:section collationStringSelector:selector]];
}
return sections;
}
This is what i ended up doing
-(NSArray *)partitionObjects:(NSArray *)array collationStringSelector:(SEL)selector
{
self.collation = [UILocalizedIndexedCollation currentCollation];
NSInteger sectionCount = [[self.collation sectionTitles] count];//section count is take from sectionTitles and not sectionIndexTitles
NSMutableArray *unsortedSections = [NSMutableArray arrayWithCapacity:sectionCount];
//create an array to hold the data for each section
for(int i = 0; i < sectionCount; i++)
{
[unsortedSections addObject:[NSMutableArray array]];
}
if ([self.catString isEqualToString:ARTISTS])
{
//put each object into a section
for (id object in array)
{
if (!object)
{
continue;
}
NSInteger index = [self.collation sectionForObject:object collationStringSelector:selector];
[[unsortedSections objectAtIndex:index] addObject:object];
}
}
else
{
NSInteger index;
for (id object in array)
{
Song *songItem = object;
NSString* charIndex;
if([songItem.songName length]<=2)
{
charIndex = [songItem.songName substringToIndex:1];
}
else if([songItem.songName length]<=3)
{
charIndex = [songItem.songName substringToIndex:2];
}
else if([songItem.songName length]<=4)
{
charIndex = [songItem.songName substringToIndex:3];
}
else if([songItem.songName length]>=5)
{
charIndex = [songItem.songName substringToIndex:4];
}
NSRegularExpression *regex = [[NSRegularExpression alloc]
initWithPattern:#"[a-zA-Z]" options:0 error:NULL];
NSUInteger matches = [regex numberOfMatchesInString:charIndex options:0
range:NSMakeRange(0, [charIndex length])];
if (matches >=2)
{
index = [self.collation sectionForObject:object collationStringSelector:selector];
[[unsortedSections objectAtIndex:index] addObject:object];
}
else
{
index = 26; //add object to last index "#"
[[unsortedSections objectAtIndex:index] addObject:object];
}
songItem = nil;
}
}
NSMutableArray *sections = [NSMutableArray arrayWithCapacity:sectionCount];
//sort each section
for (NSMutableArray *section in unsortedSections)
{
[sections addObject:[self.collation sortedArrayFromArray:section collationStringSelector:selector]];
}
return sections;
}
Related
In my code, three text fields are there for picker views. For example in the first text field, the user selects A+ blood group, in the second text field we don't want to display A+ blood group. Remaining items need to display. Text field 3 also same. For example, in text field 2 the user selects B+ blood group, in text field 3 B+ and A+ blood group needs to remove in array list. For example the user again selects the first text field and reselects another blood group like A- ve group re add the A+ blood group in array list. The same thing in text field2 and text field3. I got some exception. The exception is
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndexedSubscript:]: index 10 beyond bounds [0 .. 9]'
My json Response is:
question is :(
{
Question = "What is your first pet's name?";
QuestionID = 23;
},
{
Question = "Who was your first grade teacher?";
QuestionID = 24;
},
{
Question = "What city were you born in?";
QuestionID = 25;
},
{
Question = "What was your childhood nickname?";
QuestionID = 26;
},
{
Question = "What was the name of your elementary school?";
QuestionID = 27;
},
{
Question = "Where does your nearest relative live?";
QuestionID = 28;
},
{
Question = "In what city or town was your first job?";
QuestionID = 29;
},
{
Question = "Which is your first car? Edited ";
QuestionID = 30;
},
{
Question = "This is a test question - answer = ddi";
QuestionID = 32;
},
{
Question = "What is your Mother's maiden name?";
QuestionID = 33;
},
{
Question = "What is your Last name?";
QuestionID = 35;
},
{
Question = "What is the last 4 of your SSN?";
QuestionID = 36;
},
{
Question = "What is your Date of Birth? (MM/DD/YYYY)";
QuestionID = 37;
}
)
-(void)done:(id)sender
{
int row = [myPickerView selectedRowInComponent:0];
if (isBloodGroupFieldSelected) {
NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
[dict setObject:QArray[row] forKey:#"title"];
NSInteger currentRow = row;
[dict setObject:[NSString stringWithFormat:#"%ld",currentRow] forKey:#"selectedIndex"];
[backUpArray replaceObjectAtIndex:0 withObject:dict];
selectedValue1 = QidArray[row];
bloodGroup.text = QArray[row];
[QArray removeObjectAtIndex:row];
[QidArray removeObjectAtIndex:row];
selectedItem1=bloodGroup.text;
NSLog(#"Selected row value 1 of Picker view is:%#",selectedItem1);
}
else if((!isBloodGroupFieldSelected) && (isGenderGroupFieldSelected))
{
NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
[dict setObject:QArray[row] forKey:#"title"];
NSInteger currentRow = row;
[dict setObject:[NSString stringWithFormat:#"%ld",currentRow] forKey:#"selectedIndex"];
[backUpArray replaceObjectAtIndex:1 withObject:dict];
txtField1.text = QArray[row];
selectedItem2 = txtField1.text;
selectedValue2 = QidArray[row];
[QArray removeObjectAtIndex:row];
[QidArray removeObjectAtIndex:row];
}
else if(!isGenderGroupFieldSelected)
{
NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
[dict setObject:QArray[row] forKey:#"title"];
NSInteger currentRow = row;
[dict setObject:[NSString stringWithFormat:#"%ld",currentRow] forKey:#"selectedIndex"];
[backUpArray replaceObjectAtIndex:2 withObject:dict];
txtField2.text= QArray[row];
selectedItem3= txtField2.text;
selectedValue3 = QidArray[row];
NSLog(#"Selected row value 3 of Picker view is.....:%#",selectedValue3);
NSLog(#"selected item value 1 of picker view is:%#",selectedItem3);
[QArray removeObjectAtIndex:row];
[QidArray removeObjectAtIndex:row];
}
[myPickerView selectRow:0 inComponent:0 animated:YES];
[bloodGroup resignFirstResponder];
[txtField1 resignFirstResponder];
[txtField2 resignFirstResponder];
}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
if (isBloodGroupFieldSelected) {
return 1;
}
else if(!isBloodGroupFieldSelected){
return 1;
}
else if(!isGenderGroupFieldSelected)
{
return 1;
}
return 0;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
if (isBloodGroupFieldSelected) {
eturn [QArray count];
}
else if(!isBloodGroupFieldSelected)
{
return [QArray count];
}
else if(!isGenderGroupFieldSelected)
{
return [QArray count];
}
return 0;
}
pragma mark - UIPickerViewDelegate
// #5
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
if (isBloodGroupFieldSelected) {
return QArray[row];
}
else if((!isBloodGroupFieldSelected) && (isGenderGroupFieldSelected))
{
return QArray[row];
}
else if(!isGenderGroupFieldSelected)
{
return QArray[row];
}
return 0;
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
}
(UIView *)pickerView:(UIPickerView *)thePickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
UILabel *lblTitle = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 310, 50)];
lblTitle.numberOfLines=2;
lblTitle.textColor=[UIColor blackColor];
lblTitle.font=[UIFont systemFontOfSize:20];
lblTitle.text=QArray[row];
return lblTitle;
}
(void)textFieldDidBeginEditing:(UITextField *)textField {
if (textField == bloodGroup) {
isBloodGroupFieldSelected = YES;
NSMutableDictionary *dict = [[NSMutableDictionary alloc]initWithDictionary:[backUpArray objectAtIndex:0]];
NSString *str = [dict objectForKey:#"title"]?[dict objectForKey:#"title"]:#"";
NSInteger *index = (int)[NSString stringWithFormat:#"%#",[dict objectForKey:#"selectedIndex"]].intValue;
int count = (int) index;
if(str.length > 0){
[QArray insertObject:str atIndex:0];
}
}
else if (textField == txtField1){
isBloodGroupFieldSelected = NO;
isGenderGroupFieldSelected = YES;
NSMutableDictionary *dict = [[NSMutableDictionary alloc]initWithDictionary:[backUpArray objectAtIndex:1]];
NSString *str = [dict objectForKey:#"title"]?[dict objectForKey:#"title"]:#"";
NSInteger *index = (int)[NSString stringWithFormat:#"%#",[dict objectForKey:#"selectedIndex"]].intValue;
int count = (int) index;
if(str.length > 0){
[QArray insertObject:str atIndex:0];
}
}
else if (textField == txtField2){
isGenderGroupFieldSelected = NO;
isBloodGroupFieldSelected = NO;
NSMutableDictionary *dict = [[NSMutableDictionary alloc]initWithDictionary:[backUpArray objectAtIndex:2]];
NSString *str = [dict objectForKey:#"title"]?[dict objectForKey:#"title"]:#"";
NSInteger *index = (int)[NSString stringWithFormat:#"%#",[dict objectForKey:#"selectedIndex"]].intValue;
int count = (int) index;
if(str.length > 0){
[QArray insertObject:str atIndex:0];
}
}
[myPickerView reloadAllComponents];
}
(void)viewDidLoad
{
[super viewDidLoad];
backUpArray = [[NSMutableArray alloc]init];
for(int i=0;i<=2;i++){
dict = [[NSMutableDictionary alloc]init];
[backUpArray insertObject:dict atIndex:i];
}
}
I have one array of array.I want check my inner array is empty or not.and I am checking objects of array are empty string.
Here is my code :
NSMutableArray *newArray = [NSMutableArray array];
NSMutableArray *selectArray = [NSMutableArray array];
for (int i = 0; i < [newArray count]; i++)
{
NSArray *arr = [newArray objectAtIndex:i];
if ([arr count] > 0)
{
NSString *str = [arr objectAtIndex:0];
if (![str isEqualToString:#""])
{
[selectArray addObject:str];
}
}
}
my newArray is array of array.I want to add strings in selectArray which are not empty.but, only 0th index object is added in selectArray multiple times.
Please suggest me, where i am doing wrong.thanks
Thats because you are just getting the 0'th element of your newArray's elements, I mean this line
NSString *str = [arr objectAtIndex:0];
you should put another for in your code. Use this code instead of yours
NSMutableArray *newArray = [NSMutableArray array];
NSMutableArray *selectArray = [NSMutableArray array];
for (int i = 0; i < [newArray count]; i++){
NSArray *arr = [newArray objectAtIndex:i];
for (int j = 0; j < [arr count]; j++){
NSString *str = [arr objectAtIndex:j];
if (![str isEqualToString:#""]){
[selectArray addObject:str];
}
}
}
Use this code You not need to create any extra variable.
for (int i = 0; i < [newArray count]; i++)
{
for (int j = 0; j < [[newArray objectAtIndex:i] count]; j++)
{
if (![[[newArray objectAtIndex:i] objectAtIndex:j] isEqualToString:#""])
{
[selectArray addObject:str];
}
}
}
You can use following generic function to check any of the value or object is empty or null.
-(BOOL)isEmpty:(id)object{
return object == nil
|| [object isKindOfClass:[NSNull class]]
|| ([object respondsToSelector:#selector(length)]
&& [(NSData *)object length] == 0)
|| ([object respondsToSelector:#selector(count)]
&& [(NSArray *)object count] == 0);
}
You can try with this
NSMutableArray *newArray = [NSMutableArray array];
NSMutableArray *selectArray = [NSMutableArray array];
for (NSArray *arrayFromNewArray in newArray) {
if ([arrayFromNewArray count] > 0)
{
NSString *str = [arrayFromNewArray firstObject];
if (![str isEqualToString:#""])
{
[selectArray addObject:str];
}
}
}
You should be
NSMutableArray *newArray = [NSMutableArray array];
NSMutableArray *selectArray = [NSMutableArray array];
for (int i = 0; i < [newArray count]; i++)
{
NSArray *arr = [newArray objectAtIndex:i];
for (int j = 0; j < [arr count]; j++)
{
NSString *str = [arr objectAtIndex:j];
if (![str isEqualToString:#""])
{
[selectArray addObject:str];
}
}
}
Problem is you forgot the second loop :) Let me know if I am correct.
I want to create a table view which is scrollable both horizontally and vertically. I can do this by taking values myself. But I want to take the values from json. I am using model class and my json values are like this:
[
{
"cid": 109,
"iid": 10653,
"yr": 1994,
"val": "15.4311527806175"
},
{
"cid": 109,
"iid": 7872,
"yr": 1999,
"val": "8.84575553637328"
},
{
"cid": 109,
"iid": 7872,
"yr": 1998,
"val": "6.18441582677751"
},
I want my first column to be fixed when scrolling horizontally and first row to be fixed when I scroll it vertically. First column should have iid. first row should have yr and data should have val.
I am using XCMltisortTableView, ASIHttpRequest and SBJson.
I am getting the header value and left column value. How can I get the data corresponding to the yr and iid in proper column?
My code for val in requestFinished method is as follows:
rightTableData = [NSMutableArray arrayWithCapacity:mainTableData.count];
NSMutableArray *right = [NSMutableArray arrayWithCapacity:mainTableData.count];
for (int i = 0; i < mainTableData.count; i++)
{
// Model *model = [mainTableData objectAtIndex:i];
NSMutableArray *array = [NSMutableArray arrayWithCapacity:mainTableData.count];
for (int j = 0; j < headData.count; j++)
{
Model *model = [mainTableData objectAtIndex:j];
if([headData isEqual: #"2000"])
{
[array addObject:[NSString stringWithFormat:#"%#", model.val]];
}
else if([headData isEqual: #"2001"])
{
[array addObject:[NSString stringWithFormat:#"%#", model.val]];
}
else if([headData isEqual: #"2002"])
{
[array addObject:[NSString stringWithFormat:#"%#", model.val]];
}
else if([headData isEqual: #"2003"])
{
[array addObject:[NSString stringWithFormat:#"%#", model.val]];
}
else if([headData isEqual: #"2004"])
{
[array addObject:[NSString stringWithFormat:#"%#", model.val]];
}
else
{
[array addObject:[NSString stringWithFormat:#"%#", model.val]];
}
}
[right addObject:array];
}
[rightTableData addObject:right];
I'm totally new and would a appreciate any answers and any suggestions. Please do reply.
Thanks!
After trying for a long time I got the result using the code below:
-(void) requestFinished: (ASIHTTPRequest *) request
{
NSString *theJSON = [request responseString];
SBJsonParser *parser = [[SBJsonParser alloc] init];
NSMutableArray *jsonDictionary = [parser objectWithString:theJSON error:nil];
headData = [[NSMutableArray alloc] init];
NSMutableArray *head = [[NSMutableArray alloc] init];
leftTableData = [[NSMutableArray alloc] init];
NSMutableArray *left = [[NSMutableArray alloc] init];
rightTableData = [[NSMutableArray alloc]init];
for (NSMutableArray *dictionary in jsonDictionary)
{
Model *model = [[Model alloc]init];
model.cid = [[dictionary valueForKey:#"cid"]intValue];
model.iid = [[dictionary valueForKey:#"iid"]intValue];
model.yr = [[dictionary valueForKey:#"yr"]intValue];
model.val = [dictionary valueForKey:#"val"];
[mainTableData addObject:model];
[head addObject:[NSString stringWithFormat:#"%ld", model.yr]];
[left addObject:[NSString stringWithFormat:#"%ld", model.iid]];
}
NSOrderedSet *orderedSet = [NSOrderedSet orderedSetWithArray:head];
headData = [[orderedSet array] mutableCopy];
NSOrderedSet *orderedSet1 = [NSOrderedSet orderedSetWithArray:left];
NSMutableArray *arrLeft = [[orderedSet1 array] mutableCopy];
//remove duplicate enteries from header array
[leftTableData addObject:arrLeft];
NSMutableArray *right = [[NSMutableArray alloc]init];
for (int i = 0; i < arrLeft.count; i++)
{
NSMutableArray *array = [[NSMutableArray alloc] init];
for (int j = 0; j < headData.count; j++)
{
/* NSPredicate *predicate = [NSPredicate predicateWithFormat:#"SELF.iid == %ld", [[arrLeft objectAtIndex:i] intValue]];
NSArray *filteredArray = [mainTableData filteredArrayUsingPredicate:predicate];*/
NSPredicate *predicate = [NSPredicate predicateWithFormat:#"SELF.iid == %ld AND SELF.yr == %ld", [[arrLeft objectAtIndex:i] intValue], [[headData objectAtIndex:j] intValue]];
NSArray *filteredArray = [mainTableData filteredArrayUsingPredicate:predicate];
if([filteredArray count]>0)
{
Model *model = [filteredArray objectAtIndex:0];
[array addObject:model.val];
}
}
[right addObject:array];
}
[rightTableData addObject:right];
}
Hope it helps others.
I would like to show an index bar on my tableview with all my songs sorted by alphabetical order and those foreign language songs in # just like how the iPod music in iOS do it.
However i gotten an error
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[LibraryViewController partitionSongObjects:collationStringSel:]: unrecognized selector sent to instance 0x1454be90'
any comments are greatly appreciated thanks.
//viewDidLoad
[[MediaService sharedService]getAllSongsItemInSongs:^(NSArray *data) {
self.songArray = [[NSMutableArray alloc]initWithArray:data];
}];
NSMutableArray *songNameArray = [NSMutableArray array];
for (Song *songNameItem in self.songArray)
{
[songNameArray addObject:songNameItem.songName];
}
self.sectionArray = [self partitionSongObjects:songNameArray collationStringSel:#selector(songName)];
[self.songLibraryTableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade];
- (NSMutableArray *)partitionObjects:(NSArray *)array collationStringSelector:(SEL)selector
{
self.collation = [UILocalizedIndexedCollation currentCollation];
NSInteger sectionCount = [[self.collation sectionTitles] count];
NSMutableArray *unsortedSections = [NSMutableArray arrayWithCapacity:sectionCount];
for(int i = 0; i < sectionCount; i++)
[unsortedSections addObject:[NSMutableArray array]];
for (id object in array)
{
NSInteger index = [self.collation sectionForObject:object collationStringSelector:selector];
[[unsortedSections objectAtIndex:index] addObject:object];
}
NSMutableArray *sections = [NSMutableArray arrayWithCapacity:sectionCount];
for (NSMutableArray *section in unsortedSections)
[sections addObject:[self.collation sortedArrayFromArray:section collationStringSelector:selector]];
return sections;
}
you have a simple mistyping method name you call: [self partitionSongObjects:songNameArray collationStringSel:#selector(songName)] whereas you probably should:
[self partitionSongObjects:songNameArray collationStringSelector:#selector(songName)]
I would like to show an index bar on my tableview with all my songs sorted by alphabetical order and those foreign language songs and numerical in # just like how the iPod music in iOS.
I read the first character of all my song array object exclude duplicates and append it as the index.
How can i filter foreign / non alphabet and numbers ?
this is how it looks like, ugly.
would to show something like iPod.
-(NSMutableArray *)updateSongSectionIndexWithArray:(NSArray*)songArray andSelector:(SEL)selector
{
NSArray *indexedArray = [self partitionObjects:songArray collationStringSelector:selector];
return [[NSMutableArray alloc]initWithArray:indexedArray];
}
-(NSArray *)partitionObjects:(NSArray *)array collationStringSelector:(SEL)selector
{
self.collation = [UILocalizedIndexedCollation currentCollation];
NSInteger sectionCount = [[self.collation sectionTitles] count];//section count is take from sectionTitles and not sectionIndexTitles
NSMutableArray *unsortedSections = [NSMutableArray arrayWithCapacity:sectionCount];
//create an array to hold the data for each section
for(int i = 0; i < sectionCount; i++)
{
[unsortedSections addObject:[NSMutableArray array]];
}
if ([self.catString isEqualToString:ARTISTS])
{
//put each object into a section
for (id object in array)
{
if (!object)
{
continue;
}
NSInteger index = [self.collation sectionForObject:object collationStringSelector:selector];
[[unsortedSections objectAtIndex:index] addObject:object];
}
}
else
{
for (id object in array)
{
NSInteger index = [self.collation sectionForObject:object collationStringSelector:selector];
[[unsortedSections objectAtIndex:index] addObject:object];
}
}
NSMutableArray *sections = [NSMutableArray arrayWithCapacity:sectionCount];
//sort each section
for (NSMutableArray *section in unsortedSections)
{
[sections addObject:[self.collation sortedArrayFromArray:section collationStringSelector:selector]];
}
return sections;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [[[UILocalizedIndexedCollation currentCollation] sectionTitles] count];
}
I did a similar solution for a contacts application. I start by defining the alphabet myself, then you can add to each section the items that fit (case insensitive compare for the letters, Characterset for the numbers). After the list is filled, you can remove (or hide) the sections which have no entry.
I did a similar thing for one of my apps. To split titles I used this code:
NSString* alphabet = #"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
NSArray* indexes = [alphabet componentsSeparatedByString:#""];
for (NSString* title in self.titles) {
char c = [[title uppercaseString] characterAtIndex:0];
NSString* index = [NSString stringWithFormat:#"%c",c];
if ([alphabet rangeOfString:index].location == NSNotFound) {
//The title does not start with a valid letter
index = #"#";
}
NSMutableArray* sectionObjects = [self.sections objectForKey:index];
if (!sectionObjects) {
sectionObjects = [[NSMutableArray alloc] init];
[self.sections setObject:sectionObjects forKey:index];
}
[sectionObjects addObject:title];
}
Obviously this code is still missing the sort part since it's trivial.
I ended up getting this my index to work by this
-(NSArray *)partitionObjects:(NSArray *)array collationStringSelector:(SEL)selector
{
self.collation = [UILocalizedIndexedCollation currentCollation];
NSInteger sectionCount = [[self.collation sectionTitles] count];//section count is take from sectionTitles and not sectionIndexTitles
NSMutableArray *unsortedSections = [NSMutableArray arrayWithCapacity:sectionCount];
//create an array to hold the data for each section
for(int i = 0; i < sectionCount; i++)
{
[unsortedSections addObject:[NSMutableArray array]];
}
if ([self.catString isEqualToString:ARTISTS])
{
//put each object into a section
for (id object in array)
{
if (!object)
{
continue;
}
NSInteger index = [self.collation sectionForObject:object collationStringSelector:selector];
[[unsortedSections objectAtIndex:index] addObject:object];
}
}
else
{
NSInteger index;
for (id object in array)
{
Song *songItem = object;
NSString* charIndex;
if([songItem.songName length]<=2)
{
charIndex = [songItem.songName substringToIndex:1];
}
else if([songItem.songName length]<=3)
{
charIndex = [songItem.songName substringToIndex:2];
}
else if([songItem.songName length]<=4)
{
charIndex = [songItem.songName substringToIndex:3];
}
else if([songItem.songName length]>=5)
{
charIndex = [songItem.songName substringToIndex:4];
}
NSRegularExpression *regex = [[NSRegularExpression alloc]
initWithPattern:#"[a-zA-Z]" options:0 error:NULL];
NSUInteger matches = [regex numberOfMatchesInString:charIndex options:0
range:NSMakeRange(0, [charIndex length])];
if (matches >=2)
{
NSLog(#"matches %i",matches);
index = [self.collation sectionForObject:object collationStringSelector:selector];
[[unsortedSections objectAtIndex:index] addObject:object];
}
else
{
index = 26;
[[unsortedSections objectAtIndex:index] addObject:object];
}
NSLog(#"songItem %# is in index %i",songItem.songName, index);
}
}
NSMutableArray *sections = [NSMutableArray arrayWithCapacity:sectionCount];
//sort each section
for (NSMutableArray *section in unsortedSections)
{
[sections addObject:[self.collation sortedArrayFromArray:section collationStringSelector:selector]];
}
return sections;
}