深入理解Blocks与Operation Queues
1. Blocks的基础概念
1.1 变量捕获
当在块(Block)内部引用块外部的变量时,块会捕获该变量在其创建时刻的状态。例如:
// Slide up a view controller, and then when the slide animation is
// finished, change its background color to yellow.
// The block captures the value of the "myViewController" variable,
// for use after the animation has completed (which will happen some
// time after this method finishes running)
SomeViewController* myViewController = [ code omitted ];
[self presentModalViewController:myViewController animated:YES completion:^{
myViewController.view.backgroundColor = [UIColor yellowColor];
}];
此代码中,块捕获了 myViewController 变量的值,以便在动画完成后使用。
1.2 延迟执行与代码聚合
块允许将某些
超级会员免费看
订阅专栏 解锁全文
3

被折叠的 条评论
为什么被折叠?



