目标C块完成语法

时间:2019-02-14 07:15:32

标签: objective-c-blocks

我需要从块外部访问块内部生成的值。看来唯一的方法是在完成时输出,否则输出将在执行该块之前显示。什么是正确的语法来检测此类块的完成?

__block CGFloat Angle;

[self.motionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXArbitraryZVertical
                                                        toQueue:[NSOperationQueue currentQueue]
                                                    withHandler:^(CMDeviceMotion *motion, NSError *error)
 {
     [[NSOperationQueue mainQueue] addOperationWithBlock:
      ^{
          CGFloat angle;
          NSLog(@"angle = %f",angle);

          Angle = angle;
      }
      ];

     /* This gives me error
      [[NSOperationQueue mainQueue]  setCompletionBlock:^
      {
           NSLog(@"Angle = %f",Angle);
      }];
      */
 }

 ];

0 个答案:

没有答案