iOS 容易崩溃的地方总结。

来源:互联网 发布:广州凶宅数据库网址 编辑:程序博客网 时间:2024/05/29 16:18
1. 数组越界
2. 向dic中插入一个key = nil
3. 调用一个不存在的函数(#会有警告#)
4. block为空。

5. + (NSIndexPath *)indexPathForRow:(NSInteger)row inSection:(NSInteger)section; row和section是负值也会崩溃。

6. NSNotificationCenter

[[NSNotificationCenter defaultCenter] addObserver

[NSNotificationCenter defaultCenter] removeObserver 不成对的情况,也会造成崩溃。

7. selector的函数签名不照应。通常就是漏写一个“:”.方法签名不一致,导致崩溃

8. kvo一定要成对儿,不能重复add也不能重复remove ,目前还没有比较好的解决办法

9. JsonKit转换以后会生出相应的[NSNull null]对象,(注意不是nil),如果判断nil,不妥,直接使用必然崩溃;这种情况也砸FMDB中有。可以这么改一下:

#define PASS_NULL_TO_NIL(instance) (([instance isKindOfClass:[NSNull class]]) ? nil : instance)

10. 便捷方法,放到autoreleasepool中。比如NSArray * array = [NSArray arrayWithObjects:@"1",@"2",nil];  @autoreleasepool{  array xxx}