mercredi 3 décembre 2014

How to resolve this error "Array element can not be nil"?

Below code generates error



Array element can not be nil



when I assign the value in 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];


The code below does not generate error:



[tempResult addObject:[NSNumber numberWithInt:0]];
[tempResult addObject:[NSNumber numberWithInt:1]];
aryResult[0] = tempResult[0];
aryResult[3] = tempResult[1];



Aucun commentaire:

Enregistrer un commentaire