Skip to content

Instantly share code, notes, and snippets.

@LeeKahSeng
Created December 14, 2018 07:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LeeKahSeng/1884a9e8d5a0e9b131b78ae8d1bee8c3 to your computer and use it in GitHub Desktop.
Save LeeKahSeng/1884a9e8d5a0e9b131b78ae8d1bee8c3 to your computer and use it in GitHub Desktop.
class Boy {
// Failable initialisation
init?(age: Int) {
// Age cannot be less than 0
if age < 0 {
return nil
}
}
}
let boy1 = Boy(age: 10) // Boy object initialised
let boy2 = Boy(age: -1) // Boy object fail to initialise, boy2 is nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment