Skip to content

Instantly share code, notes, and snippets.

@mikeschinkel mikeschinkel/.readme.txt
Last active May 8, 2019

Embed
What would you like to do?
Proof-of-concept example of Swift using The Break/Continue Guard Clause pattern
Here is an example of using what I am currently calling the Break/Continue Guard Clause pattern.
See:
1. https://mikeschinkel.me/2019/better-alternative-to-return-early-php-wordpress/
2. https://thatthinginswift.com/guard-statement-swift/
let Once = [1]
func submit() {
var ok = false
for only in Once {
guard let name = nameField.text else {
show("No name to submit")
break
}
guard let address = addressField.text else {
show("No address to submit")
break
}
guard let phone = phoneField.text else {
show("No phone to submit")
break
}
sendToServer(name, address: address, phone: phone)
ok = true
}
return ok
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.