2016-08-29 2 views
1

다음 코드에서 removeObject는 정상적으로 작동하지만 addObject는 작동하지 않습니다. 뭐가 잘못 되었 니?removeObject는 작동하지만 addObject는 동일하지 않습니다.

NSMutableArray *sourceList = self.questions; 
NSMutableArray *randomizedList; 

for (NSInteger i = sourceList.count; i > 0; i--) { 
    //other things 

    [randomizedList addObject:sourceList[index]]; 
    [sourceList removeObject:sourceList[index]]; 
} 

randomizedList 전에 동일하며 [randomizedList addObject:sourceList[index]]; 후 실행 : 여기 NSArray > NAObject >isa Class 0x0

+1

어떤 오류가 발생합니까? –

+0

은'randomizedList' 가변 배열입니까? –

+0

'randomizedList'의 전후에 표시하십시오. – Avi

답변

3

문제는 randomizedList 할당되지 않는 것입니다.

NSMutableArray *sourceList = self.questions; 
NSMutableArray *randomizedList = [[NSMutableArray alloc] init]; 

for (NSInteger i = sourceList.count; i > 0; i--) { 
    //other things 

    [randomizedList addObject:sourceList[index]]; 
    [sourceList removeObject:sourceList[index]]; 
} 
관련 문제