这些代码行是问题所在:
case CostPeriodMonthly:
NSRange days = [gregorian rangeOfUnit:NSDayCalendarUnit inUnit:NSMonthCalendarUnit forDate:[NSDate date]];
[endDateComponents setDay:days.length];
[endDateComponents setMonth:[todayComponents month]];
[endDateComponents setYear:[todayComponents year]];
break;
使用天的第一行突出显示“使用未声明的标识符天”但为什么?我在这里想念什么?
答案 0 :(得分:3)
如果要在case
语句中声明新变量,则必须将语句括在{}
块中:
case CostPeriodMonthly: {
NSRange days = [gregorian rangeOfUnit:NSDayCalendarUnit inUnit:NSMonthCalendarUnit forDate:[NSDate date]];
[endDateComponents setDay:days.length];
[endDateComponents setMonth:[todayComponents month]];
[endDateComponents setYear:[todayComponents year]];
break;
}