gpt4 book ai didi

ios - 可选类型字符串的值?没有打开

转载 作者:IT王子 更新时间:2023-10-29 05:30:03 25 4
gpt4 key购买 nike

我只是无法打开 else block 。 xCode 为我提供了“用 ! 和 ?? 修复它”的选项,遗憾的是,这也没有解决问题。我在 xCode 中收到此错误:可选类型“字符串”的值?未展开;你的意思是使用!或者??

 @IBAction func buttonTapped(theButton: UIButton) {
if answerField.text == "0" {
answerField.text = theButton.titleLabel?.text
} else {
answerField.text = answerField.text + theButton.titleLabel?.text
}

最佳答案

因为 theButton.titleLabel?.text 它没有展开。

你可以使用

 answerField.text  = answerField.text + (theButton.titleLabel?.text ?? "")

if answerField.text == "0" {
answerField.text = theButton.titleLabel?.text
} else {
if let txt = theButton.titleLabel?.text {
answerField.text = answerField.text + txt
} else {
answerField.text = answerField.text
}
}

关于ios - 可选类型字符串的值?没有打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25799529/

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