如何获得我的块的返回值

布雷茹罗

我有一个变量,它是带有Bool返回值和void参数的块类型。

@property (nonatomic, copy) BOOL (^shouldDisplayView)(void);

我在另一个我的类中实现了这个块

myClass.shouldDisplayView = ^BOOL(void) {
    return self->_count > 0;
};

我要执行此块并检查结果,例如:

if (result of shouldDisplayView is true) ...

简单吗

if (shouldDisplayView)

还是检查它是否为非空?

特伦杜克

if (myClass.shouldDisplayView)

将检查shouldDisplayView不是nil

如果要检查shouldDisplayViewis的结果true,则应为

if (myClass.shouldDisplayView && myClass.shouldDisplayView())

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章