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;//手贱,多加了个* 

转载于:https://www.cnblogs.com/PittWong/p/5591737.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值