0

Possible Duplicate:
NSArray of Dates sort
How to sort array having numbers as string in iPhone?

I have various NSDates which I am converting to NSString and storing it in an array. I am trying to create sections according to the dates and I am sorting it at the same time. I'm wondering if it is possible to sort an NSArray of NSStrings based on a number value, The array looks like :

Array: (
10AM,
12PM,
1PM,
3PM,
9AM
)
Community
  • 1
  • 1
lifemoveson
  • 1,661
  • 8
  • 28
  • 55

1 Answers1

3

It would be easier to just sort an NSArray of NSDates, you could just do

NSArray* sortedArray = [dateArray sortedArrayUsingSelector:@selector(compare:)];

sorting the strings themselves would get you into all types of strange situations...

jbat100
  • 16,757
  • 4
  • 45
  • 70
  • Yeah true, but I have NSDate in different format like 2011-10-12 but I have to display the NSDate as sections using strings like 10AM or 8AM. – lifemoveson Oct 14 '11 at 16:29
  • and? with am NSDateFormatter they are turned easily into Strings again. – vikingosegundo Oct 14 '11 at 16:32
  • @jbat : I am trying to compare NSDictionary of date arrays like self.dateArray = [[Dictionary allKeys] sortedArrayUsingSelector:@selector(compare:)]; where allKeys include Array: ( 10AM, 12PM, 1PM, 3PM, 9AM ) – lifemoveson Oct 14 '11 at 16:48