November 2016
Intermediate to advanced
480 pages
14h 42m
English
Optionals are best used for things that can literally be nil; that is, they are useful in representing the complete absence of something.
But nonexistence is not the same as zero.
For example, if you are writing code to model a bank account, and the user has no balance in a given account, the value 0 is more appropriate than nil.
In other words, the user does not lack an account; what they are missing is money!
Take a look at the examples below and select which type would model them best.
The number of kids a parent has: Int or Int?
The name of a person’s pet: String or String?
Read now
Unlock full access