Bri*_*acy 1 objective-c objective-c-blocks
在Objective-C中是否可以创建内联块并使用其返回类型?例如,我可以创建一个返回a的块,BOOL使其内联,并使用其返回类型进行赋值.
BOOL b = <inline block that returns BOOL> { // unsure of the syntax / legality of this
return YES; // will be more logic in here, that is why I want to use a block.
};
Run Code Online (Sandbox Code Playgroud)
我遇到块语法问题,不确定是否可以内联创建块.我检查了以下资源但没有用.
谢谢您的时间和耐心,如果这不可能或非常容易.
实现该结果的另一种方法是"复合语句表达式":
BOOL b = ({
BOOL result;
// other local variables and stuff, computing "result"
result; // The last expression is the value of this compound statement expression.
});
Run Code Online (Sandbox Code Playgroud)
这是C语言的GCC扩展(并且也被Clang理解).它看起来 类似于块,但是有些不同.
| 归档时间: |
|
| 查看次数: |
579 次 |
| 最近记录: |