I created an NSMutableArray object using this code
- (void)viewDidLoad { [super viewDidLoad]; NSArray * ary1 = [NSArray arrayWithObjects:@"01/07",@"02/07",@"03/07",@"04/07",@"05/07",@"06/07",@"07/07", nil]; NSArray * ary2 = [NSArray arrayWithObjects:@"First",@"Second",@"Third",@"Forth",@"Fifth",@"Sixth",@"Seventh", nil]; NSArray * ary3 = [NSArray arrayWithObjects:@"1000",@"2000",@"3000",@"4000",@"5000",@"6000",@"7000", nil]; tableAry = [[NSMutableArray alloc] init]; for (int i=0; i<ary1.count; i++) {
And this is my DataModel class
.H file
.M file
Now I want to sort it according to the name in this array, I saw this Question in SO, which is similar to mine and uses its response code to solve my problem but for me it did not work, that it
[tableAry sortUsingDescriptors: [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES selector:@selector(caseInsensitiveCompare:)]]]; NSLog(@"tableAry : %@",tableAry);
So how can I sort the array
Update
Like @Martin R And @Rick said I allocated my array, but now I got this error.
*** Application termination due to an uncaught exception "NSInvalidArgumentException", reason: '- [DataModel caseInsensitiveCompare:]: unrecognized selector sent to instance 0x7550850