I'm trying to understand why my if statement does not work.
the numText should change based on it but it does not.
the numText should change based on it but it does not.
Code Block func textFieldShouldReturn(_ textField: UITextField) -> Bool { textField.resignFirstResponder() let text = textField.text var numText = originalNum //when you enter a value it will affect, the slider and squareOne width value will change and squareTwo width will change if widthPer.text == text { if numText >= 10 numText <= 90 { print(numText) squareIntW = Int(numText) squareOneWidth.constant = CGFloat(numText) * 2 slider.value = Float(numText) squareTwoWidth.constant = CGFloat(100 - numText) * 2 squareIntWTwo = Int(100 - numText) calPercentage() calPercentageTwo() } else if numText > 90 { //should not be over 90 numText = 90 print(numText) squareIntW = Int(numText) squareOneWidth.constant = CGFloat(numText) * 2 slider.value = Float(numText) squareTwoWidth.constant = CGFloat(100 - numText) * 2 squareIntWTwo = Int(100 - numText) calPercentage() calPercentageTwo() } else if numText < 10 { //should not be under 10 numText = 10 print(numText) squareIntW = Int(numText) squareOneWidth.constant = CGFloat(numText) * 2 slider.value = Float(numText) squareTwoWidth.constant = CGFloat(100 - numText) * 2 squareIntWTwo = Int(100 - numText) calPercentage() calPercentageTwo() } } //when you enter a value it will affect, the sliderHeight and squareOne height will change and squareTwo height will change if heightPer.text == text { if numText >= 10 numText <= 90 { squareIntH = Int(numText) squareOneHeight.constant = CGFloat(numText) * 2 sliderHeight.value = Float(numText) squareTwoHeight.constant = CGFloat(100 - numText) * 2 squareIntHTwo = Int(100 - numText) calPercentage() calPercentageTwo() } else if numText > 90 { //should not be over 90 numText = 90 squareIntH = Int(numText) squareOneHeight.constant = CGFloat(numText) * 2 sliderHeight.value = Float(numText) squareTwoHeight.constant = CGFloat(100 - numText) * 2 squareIntHTwo = Int(100 - numText) calPercentage() calPercentageTwo() } else if numText < 10 { //should be under 10 numText = 10 squareIntH = Int(numText) squareOneHeight.constant = CGFloat(numText) * 2 sliderHeight.value = Float(numText) squareTwoHeight.constant = CGFloat(100 - numText) * 2 squareIntHTwo = Int(100 - numText) calPercentage() calPercentageTwo() } } return true }
With touching the markdown feature of this site, I guess your issue of this thread (your code has some flaws and that may cause other issues in the near future) is caused by line 8 and line 42.line 17 and line 50
Aren't they something like this in your actual code?
if numText >= 10 || numText <= 90 {
Unfortunately, || seems to work as a meta-character and may be stripped from the shown article even if the original text posted have them.
Anyway, numText >= 10 || numText <= 90 is an always-true-predicate and has no meaning when you use it in if.
It should be numText >= 10 && numText <= 90, I guess.