2011-07-15 7 views
1

私はnsdateに自分のnsdateを追加しようとしています。NSDictionaryにNSDateを追加できません

- (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];    
     } 

私は私が実際に何をしたいのかknow..see DNTは私がfields..Iという名前のNSDictionaryの中で私のGoogleの天気予報APIを取得していますのは、NSDictionaryの最初のインデックスでシステムからの私NSDateを追加します。 。私NSdictionary私はデータのカップル、私は最初のインデックスで私のnSdateを追加したい。私はそれを行うことができません。 私は各ループで日付をインクリメントしようとしています...どうすればいいですか?

+0

そして、何を正確に失敗した日付ではありませんと思いますか? –

答えて

0

私はそれがデータ

[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); 
+0

私は実際に何をしたいのか分かります。私はGoogle Weather APIをnsdictionaryという名前のフィールドに入れています。私はNSDateをシステムから追加したいのですが、nsdictionary..I NSdictionaryのカップルデータ、私は最初のインデックスで自分のnSdateを追加したい。私はそれを行うことはできません。 – novice

+0

これを今すぐチェックしてください –

+0

THanks a lot ....私はまた、各ループの後に日付を1日増やしたいと思っています.... – novice

0
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); 
+0

ok ..しかし、パーサで自分のnsdateを増やす方法はありますか? – novice

関連する問題