Skip to content

Instantly share code, notes, and snippets.

@aainaj
Last active June 19, 2018 02:34
Show Gist options
  • Save aainaj/5d65939f16b4236708c4e2fac8e3f222 to your computer and use it in GitHub Desktop.
Save aainaj/5d65939f16b4236708c4e2fac8e3f222 to your computer and use it in GitHub Desktop.
PreconditionFailure
/* syntax:
public func preconditionFailure(
_ message: @autoclosure () -> String = default,
file: StaticString = #file,
line: UInt = #line) -> Never
*/
func validateAge(age: Int) -> Bool {
guard age >= 3 else {
preconditionFailure("Age can't be less than 3")
}
return true
}
_ = validateAge(age: 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment