【发布时间】:2020-04-30 13:19:24
【问题描述】:
错误:二元运算符“==”不能应用于“UILabel?”类型的操作数和'字符串'
import UIKit
class ViewController: UIViewController {
let Soft = 5
let Medium = 8
let Hard = 12
@IBAction func hardnessSelected(_ sender: UIButton) {
let hardness = sender.titleLabel
if hardness == "Soft"{
print(Soft)
}
else if hardness == "Medium"{
print (Medium)
}
else {
print (Hard)
}
}
}
我该如何解决这个错误?
【问题讨论】:
-
您认为该错误试图告诉您什么?