Failing to add NSDate into NSDictionary
I am trying to addd my nsdate into nsdictionary.CAn anyone tell me how to add it?
   - (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];            
        }
i dnt know..see what I actually want to do is I am getting my google开发者_如何学C weather api in an nsdictionary named fields..I want to add my NSDate from the system at the first index of nsdictionary..I NSdictionary I couple of data,I want to add my nSdate at the first index..I am not able to do it. I am trying to increment by date by each loop...how to do it?
i think it is date not data
[field setObject:[attributeDict objectForKey:@"date"] forKey:elementName]; 
updated code
NSMutableDictionary *dic=[[NSMutableDictionary alloc] init];//creation
[dic setObject:[NSDate date] forKey:@"Today"];//added
NSLog(@"dic is : %@ \n\n",dic);
    NSDate *now = [NSDate date];
    int daysToAdd = 50;  // or 60 :-)
    NSDate *newDate1 = [now addTimeInterval:60*60*24*daysToAdd];
    NSLog(@"Quick: %@", newDate1);
OR
    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);
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论