我在 Objective-C 中使用 OpenCV 静态库来进行一些图像处理,虽然我的应用程序运行良好,但在设备本身上却相当慢。大部分处理实际上可以预先完成,所以我决定我将序列化这些数据,并在应用程序启动时加载它。
我需要序列化/存档的数据位于 CvSeq 类型的对象中(openCV 序列 - 指向值序列的指针)。我基本上想将其保存到文件中,以便以后加载。我想我可以通过创建一个遵守 NSCoding 协议的类并从那里编码/解码来做到这一点:
@implementation MyObject
@synthesize point = _point;
@synthesize description = _description;
- (id)initWithCoder:(NSCoder *)decoder {
if (self = [super init]) {
self.point = [decoder decodeObjectForKey:@"point"];
self.description = [decoder decodeObjectForKey:@"description"];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)encoder {
[encoder encodeObject:self.point forKey:@"point"];
[encoder encodeObject:self.description forKey:@"description"];
}
@end
但是在 decodeObjectForKey: 和 encodeObject: 调用我得到错误
error: cannot convert 'objc_object*' to 'CvSeq*' in argument passing
我的代码是否有问题,或者我是否需要采取另一条路线才能在我的对象中存在非目标 C 实例变量的情况下实现相同的目标?