[Solved] Binary operator ‘


The error is pretty clear. numOfPrecentile is a UILabel?. You can’t compare that to a Double. I would suggest storing your calculation into a Double first before setting numOfPercentile.text.

@objc func calculate() {
    if let yourHeightTxtField = yourHeightTxtField.text, let yourWeightTxtField = yourWeightTxtField.text {

        if let height = Double(yourHeightTxtField), let weight = Double(yourWeightTxtField) {
            view.endEditing(true)
            percentile.isHidden = false
            numOfPercentile.isHidden = false
            let bmi = BMI.getPercentile(forWeight: weight, andHeight: height)
            numOfPercentile.text = "\(bmi)"
            if bmi <= 18.5 {
                percentile.text = "you are underweight"
            }
        }
    }
}

0

solved Binary operator ‘<=' cannot be applied to operands of type 'UILabel?' and 'Double'