&错误错误 - iOS开发

时间:2011-07-04 21:28:43

标签: xcode video ios4

我正在尝试创建一个AVCaptureSession。我的代码基于WWDC 2011视频,编号419。

我有以下行与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表示&错误是使用未声明的标识符。

1 个答案:

答案 0 :(得分:6)

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

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

NSError *error = nil;

......之前就行,一切都应该好。

作为一个解释,如果您查看AVCaptureDeviceInput deviceInputWithDevice:error:方法的签名,您将看到以下内容:

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

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