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,那么有可能就会出现让你百思不得其解的问题。

  • 相关阅读:
    php extends
    php 冒泡排序
    php base64_encode和base64_decode 编码/解码url
    php use
    php命名空间示范
    php 传一个url抓取此页面所有的链接
    pyspark
    【P1330】 封锁阳光大学
    [p1967] 货车运输
    分治的思想
  • 原文地址:https://www.cnblogs.com/tinkl/p/3667556.html
Copyright © 2011-2022 走看看