I have 2 textFields with Strings that represent URLs. If the textfield is empty, it saves a custom string ("no link A"), if filled, it needs to be valid, otherwise it shows an alert.
Is there a cleaner way to do this rather than using so many "if statements"?
linkA = linkATextField.text
linkB = linkBTextField.text
@IBAction func doneButton(_ sender: Any) {
if linkA.isEmpty && linkB.isEmpty {
linkA = "no link A"
linkB = "no link B"
saveData()
} else {
if linkA.isEmpty == false && linkB.isEmpty == false {
if linkA.isValidURL && linkB.isValidURL {
saveData()
} else {
showErrorAlert()
}
}
if linkA.isEmpty && linkB.isEmpty == false {
linkA = "no link A"
if linkB.isValidURL {
saveData()
} else {
showErrorAlert()
}
}
if linkA.isEmpty == false && linkB.isEmpty {
linkB = "no link B"
if linkA.isValidURL {
saveData()
} else {
showErrorAlert()
}
}
}
}