[英]Use of undeclared identifier error when trying to perform method call
我正在使用AV Foundation框架。 我正在嘗試為“AVCaptureDeviceInput”對象執行“deviceInputWithDevice”的方法調用。
問題是方法調用包含一個名為“error”的“error”參數,我在xcode中不斷收到此警告:使用undelcared標識符“error”
我的所有AV Foundation代碼都位於View Controller的ViewDidLoad方法實現中。 這里是:
AVCaptureSession *session = [[AVCaptureSession alloc]init];
session.sessionPreset = AVCaptureSessionPresetHigh;
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:error];
[session addInput:input];
我無法弄清楚為什么它一直給我“錯誤”參數的未聲明的標識符警告。
任何幫助是極大的贊賞。
您必須聲明您嘗試使用的error
變量:
NSError *error = nil;
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
請注意,將其傳遞給方法時需要&
before error
。 當然你應該檢查一下:
if (input) {
// it succeeded, do something
} else {
NSLog(@"Error trying to call deviceInputWithDevice: %@", error);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.