2016-08-29 52 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]]; 
} 
相關問題