tags:

views:

30

answers:

0
NSUInteger i;
int prevMonth = 0;
NSMutableArray *array = [[NSMutableArray alloc] init];
bDayDict = [[NSMutableDictionary alloc] init];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterMediumStyle];
  for(i = 0; i < [bdatesArray count]; i++){
  NSLog(@"bdates array is %@",bdatesArray);

  // Display the date onto the cell and set the font
  NSDate *date = [formatter dateFromString:[bdatesArray objectAtIndex:i]];
    NSLog(@"date is %@",date);
  NSCalendar *currentCalendar = [NSCalendar currentCalendar];
  unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit |  NSDayCalendarUnit;
  NSDateComponents *dateComps = [currentCalendar components:unitFlags fromDate:date];

  int bdayMonth = [dateComps month];
   NSLog(@"bday month is %d",bdayMonth);
   NSArray *keys=[NSArray arrayWithObjects:@"January",@"February",@"March",@"April",@"May",@"June",@"July",@"August",
      @"September",@"October",@"November",@"December",nil];
   NSLog(@"keys are %@",keys);
   NSArray *values=[NSArray arrayWithObjects:array,nil];
   NSLog(@"values are %@",values);
  // bDayDict=[NSMutableDictionary dictionaryWithObjectsAndKeys:@"values",@"keys",nil];
   NSLog(@"bdayDic are %@",bDayDict);


  if (prevMonth == bdayMonth || prevMonth == 0) {
   switch (bdayMonth) {
    case 1:
     [array addObject:date];
     break;
    case 2:
     [array addObject:date];
     break;
    case 3:
     [array addObject:date];
     break;
    case 4:
     [array addObject:date];
     break;

    case 5:
     [array addObject:date];
     break;

    case 6:
     [array addObject:date];
     break;

    case 7:
     [array addObject:date];
     break;

    case 8:
     [array addObject:date];
     break;

    case 9:
     [array addObject:date];
     break;
    case 10:
     [array addObject:date];
     break;
    case 11:
     [array addObject:date];
     break;

    case 12:
     [array addObject:date];
     break;


   }
   NSLog(@"array is %@",array);
  }

  else {
   switch (prevMonth) {
    case 1:
     [bDayDict setObject:array forKey:@"January"];
     break;

    case 2:
     [bDayDict setObject:array forKey:@"February"];
     break;
    case 3:
     [bDayDict setObject:array forKey:@"March"];
     //NSLog(@"dic is %@",bDayDict);
     break;
    case 4:
     [bDayDict setObject:array forKey:@"April"];
     //NSLog(@"dic is %@",bDayDict);
     break;
    case 5:
     [bDayDict setObject:array forKey:@"May"];
     //NSLog(@"dic is %@",bDayDict);
     break;
    case 6:
     [bDayDict setObject:array forKey:@"June"];
     //NSLog(@"dic is %@",bDayDict);
     break;

    case 7:
     [bDayDict setObject:array forKey:@"July"];
     //NSLog(@"dic is %@",bDayDict);
     break;
    case 8:
     [bDayDict setObject:array forKey:@"August"];
     //NSLog(@"dic is %@",bDayDict);
     break;
    case 9:
     [bDayDict setObject:array forKey:@"September"];
     //NSLog(@"dic is %@",bDayDict);
     break;
    case 10:
     [bDayDict setObject:array forKey:@"October"];
     //NSLog(@"dic is %@",bDayDict);
     break;
    case 11:
     [bDayDict setObject:array forKey:@"November"];
     //NSLog(@"dic is %@",bDayDict);
     break;
    case 12:
     [bDayDict setObject:array forKey:@"December"];

     break;
       }
   [array removeAllObjects];
   switch (bdayMonth) {
    case 1:
     [array addObject:date];
     break;
    case 2:
     [array addObject:date];
     break;
    case 3:
     [array addObject:date];
     break;
    case 4:
     [array addObject:date];
     break;

    case 5:
     [array addObject:date];
     break;

    case 6:
     [array addObject:date];
     break;

    case 7:
     [array addObject:date];
     break;

    case 8:
     [array addObject:date];
     break;

    case 9:
     [array addObject:date];
     break;
    case 10:
     [array addObject:date];
     break;
    case 11:
     [array addObject:date];
     break;

    case 12:
     [array addObject:date];
     break;

   }
  }

  prevMonth = bdayMonth; 
  }
NSLog(@"dic is %@",bDayDict);
[formatter release];
[array release];
[bDayDict release];