func submit() {
guard let name = nameField.text else {
show("No name to submit")
return
}
guard let address = addressField.text else {
show("No address to submit")
return
}
guard let phone = phoneField.text else {
show("No phone to submit")
return
}
sendToServer(name, address: address, phone: phone)
}
func sendToServer(name: String, address: String, phone: String) {
...
}
guard let value1 = number1, let value2 = number2 else { return }
func testFunction() {
let someValue:Int? = 5
guard let temp = someValue else {
return
}
print("It has some value (temp)")
}
testFunction()
func checkAge() {
var age: Int? = 22
guard let myAge = age else {
print("Age is undefined")
return
}
print("My age is (myAge)")
}
checkAge()
guard expression else {
// statements
// control statement: return, break, continue or throw.
}
var i = 2
while (i <= 10) {
// guard condition to check the even number
guard i % 2 == 0 else {
i = i + 1
continue
}
print(i)
i = i + 1
}