美文网首页
Block相关宏定义

Block相关宏定义

作者: 践行者 | 来源:发表于2018-08-29 18:49 被阅读15次

以下宏定义摘抄自:GUNStep

#define BLOCK_SCOPE __block

/**
 * Defines a block type.  Will work whether or not the compiler natively
 * supports blocks.
 */
#define DEFINE_BLOCK_TYPE(name, retTy, argTys, ...) \
typedef retTy(^name)(argTys, ## __VA_ARGS__)

#define DEFINE_BLOCK_TYPE_NO_ARGS(name, retTy) \
typedef retTy(^name)()


/**
 * Calls a block.  Works irrespective of whether the compiler supports blocks.
 */
#define CALL_BLOCK(block, args, ...) block(args, ## __VA_ARGS__)

/**
 * Calls a block without arguments.
 */
#define CALL_BLOCK_NO_ARGS(block) block()


#define DEFINE_BLOCK_TYPE_STRUCT(name, retTy, argTys, ...) \
typedef struct {\
void *isa;\
int flags;\
int reserved;\
retTy (*invoke)(void*, argTys, ## __VA_ARGS__);\
} *name

#define DEFINE_BLOCK_TYPE_NO_ARGS_STRUCT(name, retTy) \
typedef struct {\
void *isa;\
int flags;\
int reserved;\
retTy (*invoke)(void*);\
} *name

#define CALL_BLOCK_STRUCT(block, args, ...) block->invoke(block, args, ## __VA_ARGS__)

#define CALL_BLOCK_NO_ARGS_STRUCT(block) block->invoke(block)

相关文章

  • Block相关宏定义

    以下宏定义摘抄自:GUNStep

  • OC常用宏定义

    测试输出 Log 屏幕相关 系统相关 定义弱引用、强引用 定义警告宏 颜色宏 其他宏

  • 宏定义相关

    最近面试被问到将#define max(a, b)补充完整。这个知识点自己很久之前也详细了解过,要写出完美的定义会...

  • Block  weakSelf  宏定义

    #define WeakSelf(weakSelf) __weak __typeof(&*self)weakSel...

  • 『nodeMCU』GPIO接口学习

    PIN 相关宏定义gpio_out_setGPIO 输入输出相关宏GPIO 中断gpio_pin_intr_sta...

  • iOS开发小记!

    1:Block 循环引用的问题 宏定义 2: 修改textField的占位符(placeholder)的字体颜色、...

  • block使用

    1.block相关的一些基本 在类中定义一个block变量,就像定义一个函数,可以定义在方法的内部,也可以定义在方...

  • Unity平台相关宏定义

    Platform #define directives The platform #define directiv...

  • iOS_宏定义相关

    2018.4.20 定义涉及值的宏时最好加上括号。 代码地址:https://github.com/Thinker...

  • iOS中宏定义相关

    宏定义 例如: 注意:要是宏定义的值中有+、-一定要用括号括起来,防止在代码上下文中出现运算优先级错误 宏定义函数...

网友评论

      本文标题:Block相关宏定义

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