【问题标题】:Value of type 'NSMutableDictionary' has no member 'string' in swift“NSMutableDictionary”类型的值在 swift 中没有成员“字符串”
【发布时间】:2021-05-20 08:24:55
【问题描述】:
我是 swift 新手,在 xcode 12.3 中遇到错误。在它工作正常之前
我的代码是这样的
let dictOption = options[0] as! NSMutableDictionary
btn2.setTitle(dictOption.string(forKey: "optionValue"), for: .normal)
但它显示错误
Value of type 'NSMutableDictionary' has no member 'string'
有没有人遇到过类似的问题。
请帮忙!
【问题讨论】:
标签:
ios
swift
string
nsmutabledictionary
【解决方案1】:
替换
dictOption.string(forKey: "optionValue")
与
dictOption.value(forKey: "optionValue")
或更多Swifty
guard let dic = options.first as? [String:Any] ,
let value = dic["optionValue"] as? String else { return }
btn2.setTitle(value, for: .normal)