ios - sorting array with block does not return the right result -


this question has answer here:

so have array of strings (monthsarray) looks this:

months array before :( "november 2012", "january 2013", "september 2013", "december 2012", "august 2013" ) 

and use sort :

nsdateformatter * formatter=[[nsdateformatter alloc]init]; [formatter setdateformat:@"mmmm yyyy"];  monthsarray = [nsmutablearray arraywitharray:[tempmonthsarray sortedarrayusingcomparator:^nscomparisonresult(id a, id b) {      nstimeinterval firsttime=[[formatter datefromstring:(nsstring*)a]timeintervalsince1970];     nstimeinterval secondtime=[[formatter datefromstring:(nsstring*)b]timeintervalsince1970];      return [[nsnumber numberwithdouble:firsttime]compare:[nsnumber numberwithdouble:secondtime]];     }]]; 

after sort it looks :

months array after :( "november 2012", "december 2012", "january 2013", "september 2013", "august 2013" ) 

as see in before , after 'sort' array..they're not arranged properly. why not? cant see wrong code.

looks incorrect format. try this.

[formatter setdateformat:@"mmmm yyyy"]; 

@"yyyy" week-based calendar year.

@"yyyy" ordinary calendar year.

refer here more explanation


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -