Ios4 无法将NSDate添加到NSDictionary中
我正在尝试将我的nsdate添加到nsdictionary中。有人能告诉我如何添加它吗Ios4 无法将NSDate添加到NSDictionary中,ios4,Ios4,我正在尝试将我的nsdate添加到nsdictionary中。有人能告诉我如何添加它吗 - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict {
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict
{
//if(conditionCount ==0){
if( [@"forecast_information" isEqualToString:elementName] ) {
//conditionDate = get date
NSDate *now=[NSDate date];
isParsingInformation=YES;
NSArray *array=[NSArray arrayWithObject:now];
NSLog(@" the time is %@",array);
[forecastConditions addObject:[NSMutableDictionary dictionary]];
}
else if([@"forecast_date" isEqualToString:elementName])
{
if(!forecast_information)
forecast_information=[[NSMutableArray alloc]init];
}
else if(isParsingInformation){
NSMutableDictionary *field=[forecastConditions lastObject];
[field setObject:[attributeDict objectForKey:@"data"] forKey:elementName];
}
我不知道..看我真正想做的是在一个名为fields的nsdictionary中获取我的google weather api..我想在nsdictionary的第一个索引处添加我的NSDate..我想在第一个索引处添加我的NSDate..我无法这样做。
我试图通过每个循环按日期递增…如何做到这一点?我认为这是日期而不是数据
[field setObject:[attributeDict objectForKey:@"date"] forKey:elementName];
更新代码
NSMutableDictionary *dic=[[NSMutableDictionary alloc] init];//creation
[dic setObject:[NSDate date] forKey:@"Today"];//added
NSLog(@"dic is : %@ \n\n",dic);
或
我不知道..看我真正想做的是在一个名为fields的nsdictionary中获取我的google weather api..我想在nsdictionary的第一个索引处添加我的NSDate..我想在第一个索引处添加我的NSDate..我无法这样做。
NSDate *now = [NSDate date];
int daysToAdd = 50; // or 60 :-)
NSDate *newDate1 = [now addTimeInterval:60*60*24*daysToAdd];
NSLog(@"Quick: %@", newDate1);
NSDate *now = [NSDate date];
int daysToAdd = 50; // or 60 :-)
// set up date components
NSDateComponents *components = [[[NSDateComponents alloc] init] autorelease];
[components setDay:daysToAdd];
// create a calendar
NSCalendar *gregorian = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease];
NSDate *newDate2 = [gregorian dateByAddingComponents:components toDate:now options:0];
NSLog(@"Clean: %@", newDate2);