Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios __没有块的块存储类型?_Ios_Objective C_Objective C Blocks - Fatal编程技术网

Ios __没有块的块存储类型?

Ios __没有块的块存储类型?,ios,objective-c,objective-c-blocks,Ios,Objective C,Objective C Blocks,我正在阅读《IOS7编程突破极限》一书中的以下代码,无法理解作者为什么使用\u块存储类型而不使用块。我对\uu block的了解仅限于理解它们允许块在范围内捕获的变量是可变的。我读过其他一些关于\uu block的SO帖子,但它们让我更加困惑 -(IBAction)buttonAction:(id)sender { self.layer = [CALayer layer]; self.layer.frame = CGRectMake(80, 100, 160, 160); [sel

我正在阅读《IOS7编程突破极限》一书中的以下代码,无法理解作者为什么使用
\u块
存储类型而不使用块。我对
\uu block
的了解仅限于理解它们允许块在范围内捕获的变量是可变的。我读过其他一些关于
\uu block
的SO帖子,但它们让我更加困惑

-(IBAction)buttonAction:(id)sender {

  self.layer = [CALayer layer];
  self.layer.frame = CGRectMake(80, 100, 160, 160);
  [self.view.layer addSublayer:self.layer];

  float scale = [UIScreen mainScreen].scale;

  UIGraphicsBeginImageContextWithOptions(self.view.frame.size, YES, scale);
  [self.view drawViewHierarchyInRect:self.view.frame afterScreenUpdates:NO];

  __block UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

  UIGraphicsEndImageContext();

  CGImageRef imageRef = CGImageCreateWithImageInRect(image.CGImage,
                                                     CGRectMake(self.layer.frame.origin.x * scale,
                                                                self.layer.frame.origin.y * scale,
                                                                self.layer.frame.size.width * scale,
                                                                self.layer.frame.size.height * scale));
  image = [UIImage imageWithCGImage:imageRef];
  image = [image applyBlurWithRadius:50.0f
                           tintColor:[UIColor colorWithRed:0 green:1 blue:0 alpha:0.1]
               saturationDeltaFactor:2.0f
                           maskImage:nil];

  self.layer.contents = (__bridge id)(image.CGImage);
}

我猜这是一个编辑错误。代码可能在某一点上确实包含一个块,但在以后的编辑中它被删除了,但作者忘记了删除uu块限定符。

我认为没有理由在这段代码中使用
\uu块
。可能是复制粘贴错误。而且是。出于学术目的,与所问的问题不同,有人知道这是否会导致
image
(变量本身,而不是它所指向的对象)存在于堆上吗?或者,编译器是否足够聪明,能够发现如果这个东西从来没有被潜在地捕获过,那么它就可以像普通的局部变量一样存在于堆栈上?这段代码也会泄漏。@Tommy,问得好。知道LLVM编译器有多聪明,我会把钱花在它上面,在需要它之前不要将变量转移到堆中。