0

textFieldOne.text!我试图用来自文本字段和的可选值为字典键分配一个值textFieldTwo.text!,但是 Xcode 抛出构建错误。

let variable = [
        "keyOne": textFieldOne.text ?? "",
        "keyTwo": textFieldTwo.text ?? ""
] as [String : Any]

Build Failed as编译器无法在合理的时间内对该表达式进行类型检查;尝试将表达式分解为不同的子表达式

4

2 回答 2

0

您不必默认text属性是“”

let variable = [
    "keyOne": textFieldOne.text!,
    "keyTwo": textFieldTwo.text!
 ] 

检查https://developer.apple.com/documentation/uikit/uitextfield/1619635-text

于 2020-02-26T12:36:17.487 回答
0

你可以创建Dictionary类似的,

var variable = [String:Any]()
variable["keyOne"] = textFieldOne.text
variable["keyTwo"] = textFieldTwo.text
于 2020-02-26T12:42:54.877 回答