TextField Func Stops

I'm trying to understand why my if statement does not work.
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
}

Answered by OOPer in 649650022

line 17 and line 50

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.

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.

I'm trying to understand why my if statement does not work.

Please explain which if you think does not work.

the numText should change based on it but it does not.

What is originalNum? Your numText would never change after initialized with originalNum.
I defined it as originalNum = Int(textField.text!)! in another function. What does not work is what the green comments suggest like it makes it over 90 when its supposed to be 90 because of numText = 90

I defined it as originalNum = Int(textField.text!)! in another function. 

That definition has no meaning unless the function is guaranteed to be executed just before textFieldShouldReturn(_:).

What does not work is what the green comments suggest like it makes it over 90 when its supposed to be 90 because of numText = 90

Please specify the line number of your code.
line 17 and line 50, I just want have what the user entered become 90.

line 17 and line 50

Thanks.

 I just want have what the user entered become 90.

numText may not be the same as what the user entered. You need to get the right value from the right textField at the right place.

Did you copy the code itself ?

How does this line 8 compile ?
Code Block
    if numText >= 10 numText <= 90 {


Isn't numText already an Int ? So why
Code Block
    squareIntW = Int(numText)


You should use more meaningful var names

If originalNum is a String, call it originalNumText for instance

and if numText is an Int, call it numVal

There are some parts of code that will never be called, so remove them.
And tell exactly where (which line) you don't get what you expect.

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 { // && IS PROBABLY WHAT YOU WANT HERE ?
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 { // SAME HERE && ?
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
}

When I print numText it shows its exactly what the user entered and thats the issue.

When I print numText it shows its exactly what the user entered and thats the issue.

Is that true? With the print statement on line 19, I am sure you get 90 printed, instead of what the user entered.
Accepted Answer

line 17 and line 50

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.

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.

Thank you it was that all along.
TextField Func Stops
 
 
Q