Jul 7, 2024
numberLargerThan5
which takes an Int
and returns a Bool
.func numberLargerThan5(number: Int) -> Bool {
if number < 5 {
return false
}
return true
}
func numberLargerThan5(number: Int) -> Bool {
guard number > 5 else {
return false
}
return true
}
guard number > 5, number < 10 else {
return false
}
guard let username = usernameField.text, !username.isEmpty,
let password = passwordField.text, !password.isEmpty else {
showError(message: "Both fields are required")
return
}
// Proceed with login
var text: String? = "Hello World"
guard let unwrappedText = text else {
return
}
print(unwrappedText)
text
is not nil
and unwraps it.text
is nil
, function exits early.if let unwrappedText = text {
print(unwrappedText)
}