美文网首页
iOS断言调试

iOS断言调试

作者: shannoon | 来源:发表于2017-05-13 17:49 被阅读22次

    1. assert宏,如果括号内表达式结果为假,就闪退

            assert(each.observer != nil);
    

    调试窗口输出信息:

    Assertion failed: (each.observer != nil), function kvo_setter, file /Users/ehang/Desktop/ImplementKVO-master/ImplementKVO/NSObject+KVO.m, line 142.
    
    

    2.用@throw抛出异常,自己检查条件,自己编辑错误信息

    if (!setterMethod) {
            NSString *reason = [NSString stringWithFormat:@"Object %@ does not have a setter for key %@", self, key];
            @throw [NSException exceptionWithName:NSInvalidArgumentException
                                           reason:reason
                                         userInfo:nil];
            
            return;
        }
    

    相关文章

      网友评论

          本文标题:iOS断言调试

          本文链接:https://www.haomeiwen.com/subject/ldaxxxtx.html