下面代碼生成錯誤如何解決此錯誤「數組元素不能爲零」?
Array element can not be nil
當我在aryResult[0]
NSMutableArray *tempResult = [[NSMutableArray alloc] initWithCapacity:2];
switch (habitObj.NoOfTimesPer)
{
case 1://NO_OF_TIMES_PER_DAY
{
tempResult = [self getTotalNoOfDaysOrWeeks_createdDate:habitObj.strCreatedDt totalsOf:@"TOTAL_DAYS"];
}
break;
case 2://NO_OF_TIMES_PER_WEEK
{
tempResult = [self getTotalNoOfDaysOrWeeks_createdDate:habitObj.strCreatedDt totalsOf:@"TOTAL_WEEKS"];
}
break;
default:
break;
}
aryResult[0] = tempResult[0];
aryResult[3] = tempResult[1];
賦值下面的代碼不會產生錯誤:
[tempResult addObject:[NSNumber numberWithInt:0]];
[tempResult addObject:[NSNumber numberWithInt:1]];
aryResult[0] = tempResult[0];
aryResult[3] = tempResult[1];
使該陣列的可變副本不在其他條件下直接分配 – 2014-12-03 09:42:57