iOS断言调试

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断言调试)