0

I have the following code...

[sortedTripDatesList removeAllObjects];     
[sortedTripDatesList addObjectsFromArray:[tempArray sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]];

tempArray is a NSMutableArray of NSDates (event dates). If there is more than one item in the array xCode throws an unrecognized selector exception...

'-[__NSDate caseInsensitiveCompare:]: unrecognized selector sent to instance 0x4f66dd0'

I believe that this is because the objects in the array are NSDates. After reading the documentation and multiple google searches I am thoroughly confused on how to sort an array of dates.

Actually I have had this code running for some time now and never noticed a problem until today. Perhaps I never had more than 1 date in the array before today, but I find this hard to believe as I have been testing this app now for many months and certainly would have entered more than one event at some point during the testing.

What is the proper way to do this? Any help wold be appreciated.

John

user278859
  • 10,379
  • 12
  • 51
  • 74

1 Answers1

2

If you have NSDates in your Array, you shouldn't use caseInsensitiveCompare selector, because NSDate doesn't respond to it. Instead, compare selector should be used:

[sortedTripDatesList removeAllObjects];     
[sortedTripDatesList addObjectsFromArray:[tempArray sortedArrayUsingSelector:@selector(compare:)]];
akashivskyy
  • 44,342
  • 16
  • 106
  • 116
  • I thought I had already tried that before posting my question, but it works now. I tried so many combinations there is not telling what I did when I tried using compare:. Thanks, I really do appreciate your quick response. – user278859 Aug 19 '11 at 21:15