It looks like you're new here. If you want to get involved, click one of these buttons!
pereirap
Posts: 9New Users
// check items before
for (int t=0; t<[arrayOfNewsItems count]; t++){
NSLog(@\"Items before: %@\",[[arrayOfNewsItems objectAtIndex:t] objectForKey:@\"pubDate\"]);
}
// Now loop through and check for weird characters in the date, and remove them
NSMutableDictionary *tempDict = [[NSMutableDictionary alloc] init];
NSString *currentDate = [[NSString alloc] init];
for (int i=0; i<[arrayOfNewsItems count]; i++){
NSLog(@\"Date before: %@\",[[arrayOfNewsItems objectAtIndex:i] objectForKey:@\"pubDate\"]);
[tempDict setDictionary:[arrayOfNewsItems objectAtIndex:i]];
currentDate = [tempDict objectForKey:@\"pubDate\"];
currentDate = [currentDate stringByReplacingOccurrencesOfString:@\"T\" withString:@\" \"];
currentDate = [currentDate stringByReplacingOccurrencesOfString:@\" ue\" withString:@\"Tue\"];
currentDate = [currentDate stringByReplacingOccurrencesOfString:@\" hu\" withString:@\"Thu\"];
currentDate = [currentDate stringByReplacingOccurrencesOfString:@\"GM \" withString:@\"GMT\"];
currentDate = [currentDate stringByReplacingOccurrencesOfString:@\"ED \" withString:@\"EDT\"];
currentDate = [currentDate stringByReplacingOccurrencesOfString:@\"Z\" withString:@\" \"];
[tempDict removeObjectForKey:@\"pubDate\"];
[tempDict setValue:currentDate forKey:@\"pubDate\"];
[arrayOfNewsItems replaceObjectAtIndex:i withObject:tempDict];
NSLog(@\"Date after: %@\",[[arrayOfNewsItems objectAtIndex:i] objectForKey:@\"pubDate\"]);
}// end for
// check items after
for (int r=0; r<[arrayOfNewsItems count]; r++){
NSLog(@\"Items after: r= %i %@\",r,[[arrayOfNewsItems objectAtIndex:r] objectForKey:@\"pubDate\"]);
}
Replies
I'm also not sure what you are trying to accomplish with the dates but it seems unwieldy. Check out Apple's Time and Date programming guide, it might help you find a better way to accomplish your goal.
Finally, a suggestion: Use the Code tag to format your code. Preserves spacing/indentation and is typically easier to read.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome