2016-08-29 4 views
1

Im folgenden Code funktioniert removeObject gut, aber addObject funktioniert nicht. Was ist falsch?removeObject funktioniert, aber addObject nicht, beide haben die gleichen Parameter

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 ist das gleiche vor und nach [randomizedList addObject:sourceList[index]]; ausgeführt: NSArray > NAObject >isa Class 0x0

+1

Welchen Fehler bekommen Sie? –

+0

ist 'randomizedList' veränderbares Array? –

+0

Bitte zeigen Sie das Vorher und Nachher für 'randomedList' an. – Avi

Antwort

3

Das Problem hierbei ist, dass randomizedList nicht zugeordnet ist.

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]]; 
} 
Verwandte Themen