2011-07-04 47 views
2

我想创建一个AVCaptureSession。我根据我的代码在WWDC 2011的视频,数字419&error error - iOS dev

我有以下的线,是完全一样的,在WWDC 2011视频的代码,它也与此代码http://www.bardecode.com/en/knowledge-base/214-detailed-description-of-work-around-for-avcapturevideopreviewlayer-problem-in-ios-41.html

// Create a device input with the device and add it to the session. 
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device 
                    error:&error]; 

但Xcode说&错误是使用未声明的标识符。

回答

6

这是因为您尚未定义NSError error变量,您提供了使用&error时的地址。

如果你定义通过变量...

NSError *error = nil; 

...对前行,都应该很好。

其位的说明,如果你看的AVCaptureDeviceInput deviceInputWithDevice签名:错误:方法,你会看到以下内容:

+ (id)deviceInputWithDevice:(AVCaptureDevice *)device error:(NSError **)outError 

换句话说,这种方法需要的地址NSError指针变量作为ourError参数提供。

+0

谢谢。为什么不包含在视频和示例代码中? – SamB

+0

@SamB看起来作者错过了他们的博客 - 所提供的代码总是会抛出你遇到的错误。 (我没有看到WWDC会话视频,所以无法发表评论 - 可能该变量是在以前的视频中定义的,等等) –