Deal with zero or empty input better.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jeroen Leenarts 2018-09-26 11:43:13 +02:00
parent 8e0a52a132
commit ff1337d5ad
1 changed files with 6 additions and 2 deletions

View File

@ -174,9 +174,9 @@ class InterfaceTableViewCell: UITableViewCell {
privateKeyField.text = model.privateKey
publicKeyField.text = model.publicKey
listenPortField.text = String(model.listenPort)
listenPortField.text = model.listenPort > 0 ? String(model.listenPort) : nil
dnsField.text = model.dns
mtuField.text = String(model.mtu)
mtuField.text = model.mtu > 0 ? String(model.mtu) : nil
}
}
@ -217,12 +217,16 @@ extension InterfaceTableViewCell: UITextFieldDelegate {
} else if sender == listenPortField {
if let string = string, let port = Int16(string) {
model.listenPort = port
} else {
model.listenPort = 0
}
} else if sender == dnsField {
model.dns = string
} else if sender == mtuField {
if let string = string, let mtu = Int32(string) {
model.mtu = mtu
} else {
model.mtu = 0
}
}
}