0

我正在开发一个 iOS 应用程序。从当前日期和时间开始的全年函数循环之一。

for (int month_i = monthInt; month_i < 13; month_i++) {

       for (int i = dayInt  ; i <= monthRange.length ; i ++){


      }

}

我已检索到月份编号和范围,如下所示:

    NSDateComponents *components = [calCurrent components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit fromDate:today];
    NSInteger year = [components year];
    NSInteger month = [components month];
    NSInteger day = [components day];

    NSNumber *monthNumber = [NSNumber numberWithInteger: month];

    int monthInt = [monthNumber intValue];


    NSCalendar* cal = [NSCalendar currentCalendar];
    NSDateComponents* comps = [[NSDateComponents alloc] init];

        // Set your month here
    [comps setMonth:monthInt];

     monthRange = [cal rangeOfUnit:NSDayCalendarUnit
                               inUnit:NSMonthCalendarUnit
                              forDate:[cal dateFromComponents:comps]];

这是我目前的执行。但是,我有一种情况,我需要从日历应用程序中添加公共假期,并避免在日历上标记为假期的日期。我正在考虑使用 NSMutableDictionary ,其中对象项使用日历项进行过滤,并将键值设置为月份名称。有没有更好的方法来解决这个问题。

4

0 回答 0