我正在尝试像这样创建一个从 AVCaptureDevice 继承的类
在 MyClass.h 文件中
@interface MyClass : AVCaptureDevice
但是如何在 init 方法中将 AVCaptureDevice 实例分配给“self”?
这是我现在的方法(不起作用......)
在 MyClass.m 文件中
- (id) init
{
self = [super init];
if(self)
{
NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
AVCaptureDevice *captureDevice = [devices firstObject];
self = (MyClass*)captureDevice;
[self myClassMethod];
}
return self;
}
- (void) myClassMethod
{
NSLog(@"Doesn't work");
}
我得到了NSInvalidArgumentException
,原因:'-[AVCaptureFigVideoDevice test]:
无法识别的选择器发送到实例",这是有道理的,因为 test 不是 AVCaptureDevice 中的方法。
我之前做的另一种方法是在 MyClass 类中包含 AVCaptureDevice,它有效。
但我仍然想知道我是否错过了一些实现这一想法的好方法。
谢谢你。