gpt4 book ai didi

objective-c - 将字典从 Objective C 文件返回到 Swift?

转载 作者:行者123 更新时间:2023-11-30 11:05:52 24 4
gpt4 key购买 nike

我正在使用 open cv 和 swift。将 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

这是 Objective 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

最佳答案

您的应用程序可能在执行 Objective-C 方法时崩溃。在 Objective-C 方法中使用断点并继续一步一步,这样你就会发现崩溃的地方。

无法将 pretict 方法的返回字典崩溃分配给结果变量。它为结果提供了 [AnyHashable: Any],因此您将拥有一个 [AnyHashable: Any] 类型的结果对象。

关于objective-c - 将字典从 Objective C 文件返回到 Swift?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52735015/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com