Reputation: 1004
NSMutableArray *labels; and it is properly populated.
NSSortDescriptor* sortOrder = [NSSortDescriptor sortDescriptorWithKey: @"self" ascending: NO];
labels = [labels sortedArrayUsingDescriptors: [NSArray arrayWithObject: sortOrder]];
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI addObject:]: unrecognized selector sent to instance.
Even if I change NSArray to NSMutuableArray in the last line, I still get the error.
Thanks
Upvotes: 2
Views: 1118
Reputation: 25692
dont assign the same array to it.if it is nsarray which is immutable.
so do like this
put ur
labels as NSMutableArray
NSMutableArray *resultArray;
NSSortDescriptor* sortOrder = [NSSortDescriptor sortDescriptorWithKey: @"self" ascending: NO];
resultArray = [[labels sortedArrayUsingDescriptors: [NSArray arrayWithObject:sortOrder]] mutableCopy];
self.labels=resultArray;//updated code
NSLog(@"resultArray : %@ \n\n",resultArray);
Upvotes: 3
Reputation: 10393
NSArray * descriptors = [NSArray arrayWithObjects: sortOrder, nil];
labels = [labels sortedArrayUsingDescriptors:descriptors];
This should do the trick for you.
Upvotes: 1