zoukankan      html  css  js  c++  java
  • ios NSAssert趣谈

    Apple 官网介绍 NSAssert 的定义如下:

    #define NSAssert(condition, desc, ...)  
    do {                
    __PRAGMA_PUSH_NO_EXTRA_ARG_WARNINGS 
    if (!(condition)) {     
        [[NSAssertionHandler currentHandler] handleFailureInMethod:_cmd 
        object:self file:[NSString stringWithUTF8String:__FILE__] 
            lineNumber:__LINE__ description:(desc), ##__VA_ARGS__]; 
    }               
        __PRAGMA_POP_NO_EXTRA_ARG_WARNINGS 
    } while(0)
    #endif

    NSCassert的定义如下:

    #define NSCAssert(condition, desc, ...) 
    do {                
    __PRAGMA_PUSH_NO_EXTRA_ARG_WARNINGS 
    if (!(condition)) {     
        [[NSAssertionHandler currentHandler] handleFailureInFunction:[NSString stringWithUTF8String:__PRETTY_FUNCTION__] 
        file:[NSString stringWithUTF8String:__FILE__] 
            lineNumber:__LINE__ description:(desc), ##__VA_ARGS__]; 
    }               
        __PRAGMA_POP_NO_EXTRA_ARG_WARNINGS 
    } while(0)
    #endif

    小心使用NSAssert是因为大家可以看到它的定义中出现了一个self, 那么有可能在你的block中你会发现你明明没有self的strong引用,但是仍然出现了循环引用就看看你是否使用了NSAssert这样的小东西,有可能稍微疏忽用了它,这个宏被展开之后就持有了self,那么有可能就会出现让你百思不得其解的问题。

  • 相关阅读:
    08day 操作命令以及目录结构
    换工作
    json转为字典
    快速排序
    冒泡排序
    python函数-生成器
    关键字global
    函数的定义和参数调用
    count()函数与center()函数
    python字符串常用函数:strip()
  • 原文地址:https://www.cnblogs.com/tinkl/p/3667556.html
Copyright © 2011-2022 走看看