Nullability
Null Safety
-
Using
?allows the type to be null.let hello: String? = 'hi mom'-
This makes
hellonullable.
-
Null handling
-
Crashes :
func hit(enemy: Monster?, with weapon: Weapon) { if enemy.isAlive { enemy.health -= weapon.damage } }