Pregunta

-(NSArray*)createArrayWithObjectsNamed:(NSString*)string{

    if (!_numberArray){
        [self createArrayOfNumbers];
    }

    NSString *object;
    NSMutableArray *mutableArray;

    for (int i = 0; i <= 9; i++) {
        object = [NSString stringWithFormat:@"%@%@",string,_numberArray[i]];
        NSLog(@"array %@",object);
        [mutableArray addObject:object];
    }

    NSLog(@"value of mutableArray  %@",mutableArray);

    NSArray *array; //= [NSArray arrayWithArray:mutableArray];

    array = [mutableArray copy];

    NSLog(@"array in func %@",array);

    return array;

}

Hi, when i run createArrayWithObjectNamed:string it should run the for statement ten times and at the end of the statement each time add the new object value, but it doesn't. when I run NSlog on the mutableArray it's value is (NULL).

What is going wrong here?

¿Fue útil?

Solución

Your mutableArray variable is uninitialized. In this case it is nil, but it could very well be some arbitrary value, which could cause an EXC_BAD_ACCESS exception upon dereferencing.

NSMutableArray *mutableArray = [[NSMutableArray alloc] init];
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top