ios - Apple 源代码 - require(error == nil, bail) 导致错误
<p><p>我正在尝试使用 Apple 的一些 <a href="http://developer.apple.com/library/ios/#samplecode/SquareCam/Introduction/Intro.html" rel="noreferrer noopener nofollow">source code</a> ,但代码中充斥着这些语句:</p>
<pre><code>require( error == nil, bail );
</code></pre>
<p>在 ARC 项目中使用时会导致各种错误(“转到 protected 范围”)。</p>
<p>如何解决此代码?</p>
<p>这是一个例子:</p>
<pre><code>- (void)setupAVCapture
{
NSError *error = nil;
AVCaptureSession *session = ;
if ([ userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
;
else
;
// Select a video device, make an input
AVCaptureDevice *device = ;
AVCaptureDeviceInput *deviceInput = ;
require( error == nil, bail ); //ERROR: "Goto into protected scope"
isUsingFrontFacingCamera = NO;
if ( )
;
// Make a still image output
self.stillImageOutput = ;
;
if ( )
;
// Make a video data output
self.videoDataOutput = ;
// we want BGRA, both CoreGraphics and OpenGL work well with 'BGRA'
NSDictionary *rgbOutputSettings = [NSDictionary dictionaryWithObject:
forKey:(id)kCVPixelBufferPixelFormatTypeKey];
;
; // discard if the data output queue is blocked (as we process the still image)
// create a serial dispatch queue used for the sample buffer delegate as well as when a still image is captured
// a serial dispatch queue must be used to guarantee that video frames will be delivered in order
// see the header doc for setSampleBufferDelegate:queue: for more information
videoDataOutputQueue = dispatch_queue_create("VideoDataOutputQueue", DISPATCH_QUEUE_SERIAL);
;
if ( )
;
[ setEnabled:NO];
effectiveScale = 1.0;
self.previewLayer = [ initWithSession:session];
CGColor]];
;
CALayer *rootLayer = ;
;
];
;
;
bail:
session = nil;
if (error) {
UIAlertView *alertView = [ initWithTitle:]
message:
delegate:nil
cancelButtonTitle:@"Dismiss"
otherButtonTitles:nil];
;
;
}
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>添加左大括号和右大括号以提及范围</p>
<pre><code>require( error == nil, bail );
{
}
bail:
{
}
</code></pre>
<p><strong>示例:</strong></p>
<pre><code>require( error == nil, bail );
{
isUsingFrontFacingCamera = NO;
if ( )
;
// Make a still image output
stillImageOutput = ;
;
if ( )
;
// Make a video data output
videoDataOutput = ;
// we want BGRA, both CoreGraphics and OpenGL work well with 'BGRA'
NSDictionary *rgbOutputSettings = [NSDictionary dictionaryWithObject:
forKey:(id)kCVPixelBufferPixelFormatTypeKey];
;
; // discard if the data output queue is blocked (as we process the still image)
// create a serial dispatch queue used for the sample buffer delegate as well as when a still image is captured
// a serial dispatch queue must be used to guarantee that video frames will be delivered in order
// see the header doc for setSampleBufferDelegate:queue: for more information
videoDataOutputQueue = dispatch_queue_create("VideoDataOutputQueue", DISPATCH_QUEUE_SERIAL);
;
if ( )
;
[ setEnabled:NO];
effectiveScale = 1.0;
previewLayer = [ initWithSession:session];
CGColor]];
;
CALayer *rootLayer = ;
;
];
;
;
}
bail:
{
if (error) {
UIAlertView *alertView = [ initWithTitle:]
message:
delegate:nil
cancelButtonTitle:@"Dismiss"
otherButtonTitles:nil];
;
;
}
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - Apple 源代码 - require(error == nil, bail) 导致错误,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/15074361/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/15074361/
</a>
</p>
页:
[1]