Objective c removeObject工作,但addObject不工作,两者具有相同的参数
在下面的代码中,removeObject工作正常,但addObject不工作。怎么了Objective c removeObject工作,但addObject不工作,两者具有相同的参数,objective-c,Objective C,在下面的代码中,removeObject工作正常,但addObject不工作。怎么了 NSMutableArray *sourceList = self.questions; NSMutableArray *randomizedList; for (NSInteger i = sourceList.count; i > 0; i--) { //other things [randomizedList addObject:sourceList[index]]; [
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类0x0
这里的问题是没有分配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]];
}
你得到了什么错误?是randomizedList
可变数组?请显示randomizedList
@RonanChaniyara和其他人的前后:我已经编辑了问题并添加了缺少的信息