Linked Questions

Popular Questions

How to determine the last activ UITextField in Xcode

Asked by At

I am new to swift and i am playing around with a little converter app. I Have two TextFields and one "convert" button. I want to overwrite the non acticv Textfield with the converted value from the last activ TextField. I know it would be easier with more Textfields and more buttons but i would like to solve it this way.

Can anybody give me an advise?

var NumberC = Int(InputCelcius.text!)!
var NumberF = Int(InputFahrenheit.text!)!

if InputCelcius.isFirstResponder {
    if (InputCelcius.text?.isEmpty)! {
        NumberC=0
        print("NumberC is empty")
    }
    NumberC = NumberC * 9/5 + 32
    InputFahrenheit.text = " \(NumberC)"
}

else if InputFahrenheit.isFirstResponder {  
    if (InputFahrenheit.text?.isEmpty)! {
        NumberF=0
        print("NumberF is empty")     
    }
    NumberF = (NumberF - 32) * 5/9
    InputCelcius.text = " \(NumberF)"
}

Related Questions