문제

-(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?

도움이 되었습니까?

해결책

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];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top