gpt4 book ai didi

swift - 'NSInvalidArgumentException',原因: '*** -getValue: only defined for abstract class. Define -[KotlinInt getValue:]!'

转载 作者:行者123 更新时间:2023-12-02 12:57:28 27 4
gpt4 key购买 nike

我正在使用Kotlin多平台构建iOS框架,除奇怪的问题外,其他一切都运行良好。

来自Kotlin的代码:

fun example(): Map<Int, Double> {
val result = mutableMapOf<Int, Double>()
result[1] = 9.99
return result
}

使用框架是Swift:

let example = example()

该应用程序将崩溃并显示跟踪,如下所示
2019-10-30 15:37:19.096474+0800 Test[73756:3057881] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -getValue: only defined for abstract class.  Define -[KotlinInt getValue:]!'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff23baa1ee __exceptionPreprocess + 350
1 libobjc.A.dylib 0x00007fff50864b20 objc_exception_throw + 48
2 Foundation 0x00007fff2584a6b3 _NSRequestConcreteObject + 0
3 Foundation 0x00007fff256bea7e -[NSNumber copyWithZone:] + 129
4 CoreFoundation 0x00007fff23add550 __NSSingleEntryDictionaryI_new + 128
5 CoreFoundation 0x00007fff23ba56f3 -[NSDictionary initWithDictionary:copyItems:] + 403
6 CoreFoundation 0x00007fff23c07fc7 -[__NSPlaceholderDictionary initWithDictionary:copyItems:] + 135
7 libswiftFoundation.dylib 0x00007fff511ef3a0 $sSD10FoundationE26_forceBridgeFromObjectiveC_6resultySo12NSDictionaryC_SDyxq_GSgztFZ + 192
8 libswiftFoundation.dylib 0x00007fff511e3593 $sSD10FoundationE36_unconditionallyBridgeFromObjectiveCySDyxq_GSo12NSDictionaryCSgFZ + 67
9 Test 0x0000000102f54320 $s4Test11ContentViewV3calSSyF + 1104
10 Test 0x0000000102f53e3b $s4Test11ContentViewV4bodyQrvg + 91
11 Test 0x0000000102f549c1 $s4Test11ContentViewV7SwiftUI0C0AadEP4body4BodyQzvgTW + 17
12 SwiftUI 0x00007fff2bfb1c49 $s7SwiftUI8ViewBody33_9F92ACD17B554E8AB7D29ABB1E796415LLV5applyy0D0QzxF + 585
13 SwiftUI 0x00007fff2bfb2df9 $s7SwiftUI8ViewBody33_9F92ACD17B554E8AB7D29ABB1E796415LLVyxG14AttributeGraph07UntypedM0AafGP7_update_5graph9attributeySv_So10AGGraphRefaSo11AGAttributeatFZTW + 137
14 AttributeGraph 0x00007fff2f8f1849 $sTA + 25
15 AttributeGraph 0x00007fff2f8d9255 _ZN2AG5Graph11UpdateStack6updateEv + 1111
16 AttributeGraph 0x00007fff2f8d9513 _ZN2AG5Graph16update_attributeEjb + 377
17 AttributeGraph 0x00007fff2f8de131 _ZN2AG8Subgraph6updateEj + 929
18 SwiftUI 0x00007fff2c10d100 $s7SwiftUI9ViewGraphC14runTransaction33_D63C4EB7F2B205694B6515509E76E98BLL2inySo10AGGraphRefa_tF + 224
19 SwiftUI 0x00007fff2c10d517 $s7SwiftUI9ViewGraphC13updateOutputs2atyAA4TimeV_tFSb5prefs_Sb9idealSizeAC0F0V7outputstSo10AGGraphRefaXEfU_ + 103
20 SwiftUI 0x00007fff2c10d1d1 $s7SwiftUI9ViewGraphC13updateOutputs2atyAA4TimeV_tF + 145
21 SwiftUI 0x00007fff2c4af579 $s7SwiftUI16ViewRendererHostPAAE6render8interval17updateDisplayListySd_SbtFyyXEfU_yyXEfU_ + 1001
22 SwiftUI 0x00007fff2c4aef8a $s7SwiftUI16ViewRendererHostPAAE6render8interval17updateDisplayListySd_SbtFyyXEfU_ + 634
23 SwiftUI 0x00007fff2c4a4274 $s7SwiftUI16ViewRendererHostPAAE6render8interval17updateDisplayListySd_SbtF + 436
24 SwiftUI 0x00007fff2c65a182 $s7SwiftUI14_UIHostingViewC14layoutSubviewsyyF + 226
25 SwiftUI 0x00007fff2c65a1a5 $s7SwiftUI14_UIHostingViewC14layoutSubviewsyyFTo + 21
26 UIKitCore 0x00007fff47a52ad5 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2478
27 QuartzCore 0x00007fff2b06e91d -[CALayer layoutSublayers] + 255
28 QuartzCore 0x00007fff2b073323 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 517
29 QuartzCore 0x00007fff2b07fa7c _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 80
30 QuartzCore 0x00007fff2afc6e54 _ZN2CA7Context18commit_transactionEPNS_11TransactionEd + 324
31 QuartzCore 0x00007fff2affc32f _ZN2CA11Transaction6commitEv + 643
32 UIKitCore 0x00007fff475906cd __34-[UIApplication _firstCommitBlock]_block_invoke_2 + 81
33 CoreFoundation 0x00007fff23b0d09c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
34 CoreFoundation 0x00007fff23b0c808 __CFRunLoopDoBlocks + 312
35 CoreFoundation 0x00007fff23b07694 __CFRunLoopRun + 1284
36 CoreFoundation 0x00007fff23b06e66 CFRunLoopRunSpecific + 438
37 GraphicsServices 0x00007fff38346bb0 GSEventRunModal + 65
38 UIKitCore 0x00007fff47578dd0 UIApplicationMain + 1621
39 Test 0x0000000102f526fb main + 75
40 libdyld.dylib 0x00007fff516ecd29 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

实际上,我想实现返回Map的功能,但是我检查Xocde的IDE中 example()的类型是[KotlinInt:KotlinDouble]。我不知道如何解决这个问题,以正常地在Xcode中使用此功能。

最佳答案

我以为Kotlin中没有与iOS Swift中的“字典”相对应的结构类型“ map ”。尝试用MutableMap替换Map并解决此问题。

fun example(): MutableMap <Int, Double> {
val result = mutableMapOf<Int, Double>()
result[1] = 9.99
return result
}

但是,您也可以在Swift中将类型强制转换为其他用途。例如,

let example = example() as! [Int64 : Double]

关于swift - 'NSInvalidArgumentException',原因: '*** -getValue: only defined for abstract class. Define -[KotlinInt getValue:]!',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58620688/

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