oc开发过程中常见崩溃原因

1,KVO+通知等 --监听类
必须在dealloc方法中注销监听,否则极其容易崩溃

- (void)dealloc {
    [self.currentTask removeObserver:self forKeyPath:@"status" context:nil];
//KVO崩溃,添加监听者必须记得取消监听 否则就崩给你看
    [self removeObserverBlocks];
}

2,除法的使用
当被除数为0时,无法计算,那就崩给你看

- (void)dealloc {
    self.model.value1/self.model.value2
  如果value2==0 崩给你看
}

3,非可变字典和数组
尤其在使用字面量方法来快捷创建时,当value为nil时,崩给你看

NSDictionary *requestDict = @{@"opt"       : @2,
                                  @"account"   : account,
                                  @"check"     : @(check),
                                  @"become"    : become};
如果account,become有任何一个为nil,崩给你看

4,富文本
如果string是空,崩给你看

NSDictionary *attributes = @{
                                 NSFontAttributeName:[UIFont kdxTextCellMessageFont],
                                 NSParagraphStyleAttributeName:paragraphStyle,
                                 NSForegroundColorAttributeName:[UIColor kdxTextCellMessageColor]
                                 };
    
    self.contentTextView.attributedText = [[NSAttributedString alloc] initWithString:string attributes:attributes];
string为nil,崩给你看

5,归档 解档
数据解析通过MJExtension 属性int 加了个* 导致崩溃

@property (nonatomic ,assign) int  * code;//手贱,多加了个* 

posted @ 2016-06-16 17:43  PittWong  阅读(474)  评论(0编辑  收藏  举报