<分区>
标签 ios
<分区>
这是来自 apple block programming , 谁能告诉我这是什么意思
Stack (non-static) variables local to the enclosing lexical scope are captured as const variables.
最佳答案
假设你有:
int i = 5; // in stack
然后在 block 中你有:
...
i++; // can't do that, because i now inside the block is a const
...
您要将 __block 添加到 i
声明,以便能够像这样在 block 内更改 i
的值:
__block int i = 5; // remove __block and see the error
void (^myBlock)(void) = ^{
NSLog(@"[inside block] i = %i", i); // no error even without __block
i++; // error here without __block
};
myBlock();
NSLog(@"[outside block] i = %i", i);
关于ios - 我很难理解苹果 block 编程的这一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13064713/