Binary operator '==' cannot be applied to operands of type 'UILabel?' and 'String'

前端 未结 4 792
天涯浪人
天涯浪人 2021-01-29 16:46

Error : Binary operator \'==\' cannot be applied to operands of type \'UILabel?\' and \'String\'


import UIKit

class ViewController: UIViewController {
  let So         


        
4条回答
  •  悲哀的现实
    2021-01-29 17:10

    UIButton.titleLabel is a UILabel and it stores its text in UILabel.text property:

    let hardness = sender.titleLabel.text
    

    In the case of UIButton you can also access UIButton.currentTitle property:

    let hardness = sender.currentTitle
    

提交回复
热议问题