gpt4 book ai didi

ios - Swift - 4 - 无法将类型 '__NSCFNumber' (0x10cfb1840) 的值转换为 'NSString' (0x10c0824a8)

转载 作者:行者123 更新时间:2023-11-29 05:45:07 37 4
gpt4 key购买 nike

我收到此错误:

Could not cast value of type '__NSCFNumber' (0x10cfb1840) to 'NSString' (0x10c0824a8)

在这行代码中:

fkprofession = (pickOption[pickerView.selectedRow(inComponent: 0)]["id"] as? String)!

pickOption 定义为:

var pickOption = Array<Dictionary<String, Any>>()

我做错了什么?

最佳答案

错误非常明显:键id的值是一个数字(Int或可能Double)

您可以将无法转换错误始终读取为

Could not cast value of the right type to my proposed wrong type

fkprofession = pickOption[pickerView.selectedRow(inComponent: 0)]["id"] as! Int

或者如果你需要一个字符串

fkprofession = String(pickOption[pickerView.selectedRow(inComponent: 0)]["id"] as! Int)

关于ios - Swift - 4 - 无法将类型 '__NSCFNumber' (0x10cfb1840) 的值转换为 'NSString' (0x10c0824a8),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56225041/

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