0

ReferenceStringRow is my value of text field which must be between 8 to 55. Even after providing right input, every time else block is executing.

enter image description here

//MARK:- Term Cheack

if matureTextField.text != "" {
    print("term is not nil")
    if ReferenceStringRow >= "8" && ReferenceStringRow <= "55"
    {
        print("values of term are in limit 8 to 55")
    }else{
        let aleartController = UIAlertController(title:"Caution", message: "Term must between 8 - 55", preferredStyle: .alert)
        let aleartAction = UIAlertAction(title: "Ok", style: .default) { (action:UIAlertAction) in
            print("Action Pressed")
        }
        aleartController.addAction(aleartAction)
        self.present(aleartController, animated: true)
        print("Values of term are not in limit 12 to 35")
    }
rmaddy
  • 314,917
  • 42
  • 532
  • 579

2 Answers2

4

Because you treating String as number and is impossible to check with < and > operator.

you have to take ReferenceStringRow as Int value and compare with Int value.

let ReferenceStringRow = 34

  if ReferenceStringRow >= 8 && ReferenceStringRow <= 55 {
     print("values of term are in limit 8 to 55")
  } else {
     let aleartController = UIAlertController(title:"Caution", message: "Term must between 8 - 55", preferredStyle: .alert)
     let aleartAction = UIAlertAction(title: "Ok", style: .default) { (action:UIAlertAction) in
        print("Action Pressed")
     }
     aleartController.addAction(aleartAction)
     self.present(aleartController, animated: true)
     print("Values of term are not in limit 12 to 35")
  }
Jaydeep Vora
  • 6,085
  • 1
  • 22
  • 40
1

The ReferenceStringRow value must be converted to number before comparing it using ">=" and "<=" operators.

In this question you can find examples: Converting String to Int with Swift