Не удается добавить NSDate в NSDictionary - PullRequest
1 голос
/ 15 июля 2011

Я пытаюсь добавить свой nsdate в nsdictionary. Кто-нибудь подскажет, как его добавить?

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

Я не знаю .. Посмотрите, что я на самом деле хочу сделать, я получаю свою погоду GoogleAPI в nsdictionary с именованными полями .. Я хочу добавить свой NSDate из системы по первому индексу nsdictionary .. Я, конечно, я пару данных, я хочу добавить свой nSdate при первом индексе .. Я не могу сделатьЭто.Я пытаюсь увеличить по дате на каждый цикл ... как это сделать?

Ответы [ 2 ]

0 голосов
/ 15 июля 2011
    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);
0 голосов
/ 15 июля 2011

я думаю, что это дата, а не данные

[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);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...