zoukankan      html  css  js  c++  java
  • iOS开发中两个不错的宏定义

    /**

     Synthsize a weak or strong reference.

     Example:

        @weakify(self)

        [self doSomething^{

            @strongify(self)

            if (!self) return;

            ...

        }];

     */

    #ifndef weakify

        #if DEBUG

            #if __has_feature(objc_arc)

            #define weakify(object) autoreleasepool{} __weak __typeof__(object) weak##_##object = object;

            #else

            #define weakify(object) autoreleasepool{} __block __typeof__(object) block##_##object = object;

            #endif

        #else

            #if __has_feature(objc_arc)

            #define weakify(object) try{} @finally{} {} __weak __typeof__(object) weak##_##object = object;

            #else

            #define weakify(object) try{} @finally{} {} __block __typeof__(object) block##_##object = object;

            #endif

        #endif

    #endif

    #ifndef strongify

        #if DEBUG

            #if __has_feature(objc_arc)

            #define strongify(object) autoreleasepool{} __typeof__(object) object = weak##_##object;

            #else

            #define strongify(object) autoreleasepool{} __typeof__(object) object = block##_##object;

            #endif

        #else

            #if __has_feature(objc_arc)

            #define strongify(object) try{} @finally{} __typeof__(object) object = weak##_##object;

            #else

            #define strongify(object) try{} @finally{} __typeof__(object) object = block##_##object;

            #endif

        #endif

    #endif

    ARC和MRC环境下关于防止block内部self循环引用的问题

  • 相关阅读:
    java-判断某一年是否是闰年
    java-不用其他变量实现两变量互换
    java基础一标识符,运算符
    robotium学习(三)
    robotium学习(二)
    robotium学习(一)
    AX2012 订单折扣的应用
    AX2012 用户收藏夹复制
    ueditor 改变图片上传路径
    if else 多路分支,多条件运算
  • 原文地址:https://www.cnblogs.com/IceBlack-Tea-developer/p/5260042.html
Copyright © 2011-2022 走看看