Created
December 14, 2018 07:10
-
-
Save LeeKahSeng/1884a9e8d5a0e9b131b78ae8d1bee8c3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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