I am new to iphone development .I am trying to sort a NSMutable array with reference to the date which is saved as object for the key "pubDate".After parsing the url i am saving the date as date format in an array"myPubDate".
(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
//NSLog(@"found characters: %@", string);
// save the characters for the current item...
if ([currentElement isEqualToString:@"title"]) {
[currentTitle appendString:string];
} else if ([currentElement isEqualToString:@"link"]) {
[currentLink appendString:string];
} else if ([开发者_开发百科currentElement isEqualToString:@"description"]) {
[currentSummary appendString:string];
} else if ([currentElement isEqualToString:@"pubDate"]) {
[currentDate appendString:string];
NSDateFormatter *df =[[NSDateFormatter alloc] init];
[df setFormatterBehavior:NSDateFormatterBehavior10_4];
[df setDateFormat:@"EEE, dd MMM yyyy"];
myPubDate = [df dateFromString:currentDate];
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
//NSLog(@"ended element: %@", elementName);
if ([elementName isEqualToString:@"item"]) {
[item setObject:currentTitle forKey:@"title"];
[item setObject:currentLink forKey:@"link"];
[item setObject:currentSummary forKey:@"description"];
[item setObject:myPubDateforKey:@"pubDate"]
[item setObject:currentImage forKey:@"imagePath"];
NSLog(@"Befor if condition");
[stories addObject:[item copy]];
}
recent = [stories copy];}
For sorting
NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"pubDate" ascending:NO];
[recent sortUsingDescriptor:[NSArray arrayWithObjects:descriptor, nil]];
recent1 = [recent sortedArrayUsingDescriptors:descriptor];
[descriptor release];
I am geeting an error in the console as
[NSCFArray sortUsingDescriptor:]: unrecognized selector sent to instance 0x4ed10c0
Where do i go wrong? please help me out.Thanks.
Your problem appears to be a typo: sortUsingDescriptor:
is not the same as sortUsingDescriptors:
精彩评论