-[__NSCFArray insertObject:atIndex:]: mutating method sent to immutable obje

-[__NSCFArray insertObject:atIndex:]: mutating method sent to immutable obje
意思是变的方法发送给一个不变的对象

错误修改
NSMutableArray *history;
NSUserDefaults *defaults;
defaults = [NSUserDefaults standardUserDefaults];
self.history = [[NSMutableArray alloc] init];
NSMutableArray *array = [defaults objectForKey:kUserDefaultsSearchHistory];
if (array) {
//创建好的history不能这样赋值,应该[self.history setObject:XX forkey:XX];
self.history = array; 
}

改为
NSMutableArray *history;
NSUserDefaults *defaults;
defaults = [NSUserDefaults standardUserDefaults];

NSMutableArray *array = [defaults objectForKey:kUserDefaultsSearchHistory];
if (array) {
self.history = array;

}else {
self.history = [[[NSMutableArray alloc] init] autorelease];
}

你可能感兴趣的:(-[__NSCFArray insertObject:atIndex:]: mutating method sent to immutable obje)