I am new to iphone development .I have mutable array recent in which the values such as title,date,url and summary are stored as ” object for key”.The keys are myurl,mudate,mytitle,mysummary.I want to sort that mutable array in reference to date and print all the values according to that..How can i achieve that?Please help me out.Thanks.
[item setObject:currentTitle forKey:@"title"];
[item setObject:currentLink forKey:@"link"];
[item setObject:currentSummary forKey:@"description"];
[item setObject:currentDate forKey:@"pubDate"];//
[item setObject:currentImage forKey:@"imagePath"];
[recent addObject:[item copy]];
All are xml parsed contents.
So I’m guessing you have an array of dictionaries. There are a couple ways to do this, but the one I recommend is using
NSSortDescriptor. You’ll want to do something like this:If you you have your dates as
NSDateobjects already, this will work fine. If not, you’ll either need to loop through the array and parse the dates beforehand, or use theinitWithKey:ascending:selector:method ofNSSortDescriptor, which allows you to define a custom comparison method.