崩溃集锦

数组越界

NSMutableArray *arr = [NSMutableArray arrayWithObjects:@"1",@"2",@"3", nil];
NSLog(@"index:%@---noneDataIndex:%zd",@"1",@"4");
[arr exchangeObjectAtIndex:[arr indexOfObject:@"1"] withObjectAtIndex:[arr indexOfObject:@"4"]];

打印结果:

index:1---noneDataIndex:4402863976
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM exchangeObjectAtIndex:withObjectAtIndex:]: index 9223372036854775807 beyond bounds [0 .. 2]'

原因分析:获取数组中一个不存在的对象的index时,获取到的值是一个比较大随机数值,在使用exchangeObjectAtIndex时就会产生崩溃现象,所以要做提前做好判断。

你可能感兴趣的:(崩溃集锦)