我正在与开放的简历和迅速。将NSDictionary
从Objective-C文件返回到Swift时出错。
2018-10-10 12:43:25.972927+0530 OPencvwithSwift[2430:618249] -[__NSFrozenDictionaryM length]: unrecognized selector sent to instance 0x1c022b6e0
2018-10-10 12:43:25.973704+0530 OPencvwithSwift[2430:618249] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSFrozenDictionaryM length]: unrecognized selector sent to instance 0x1c022b6e0'
*** First throw call stack:
(0x183eb6d8c 0x1830705ec 0x183ec4098 0x183ebc5c8 0x183da241c 0x1053c23d4 0x105360aa0 0x10585294c 0x104aec9a0 0x104ae287c 0x105cd51dc 0x105cd519c 0x105cd9d2c 0x183e5f070 0x183e5cbc8 0x183d7cda8 0x185d62020 0x18dd9c758 0x104af984c 0x18380dfc0)
libc++abi.dylib: terminating with uncaught exception of type NSException
这是目标c代码-
- (NSDictionary *)predict:(UIImage*)img confidence:(double)confidence {
cv::Mat src = [img cvMatRepresentationGray];
int label;
NSLog(@"%d",label);
std::cout<<_labelsDictionary;
self->_faceClassifier->predict(src, label, confidence);
NSLog(@"%f",confidence);
NSMutableDictionary *dict = [[NSMutableDictionary alloc]initWithCapacity:10];
[dict setObject:[NSNumber numberWithInt:confidence] forKey:_labelsDictionary[@(label)]];
NSLog(@"%@",dict);
return dict;
}
从Swift调用此函数:
let result = facemodel?.predict(greyimage, confidence: confidence) // crash on this line
答案 0 :(得分:0)
您的应用程序可能在执行Objective-C方法时崩溃。在Objective-C方法内使用断点,然后逐步进行操作,以便发现崩溃。
没有办法崩溃将pretict方法的返回字典分配给结果变量。它提供[AnyHashable:Any]结果,因此您将有一个[AnyHashable:Any]类型结果对象。
答案 1 :(得分:0)
如果我对您的理解是正确的,那么在使用字典之前,在其他地方,它已指向字符串。如此崩溃