Swift has this behaviour because of two phase initialisation. From Apple’s Swift book:
Class initialization in Swift is a two-phase process. In the first
phase, each stored property is assigned an initial value by the class
that introduced it. Once the initial state for every stored property
has been determined, the second phase begins, and each class is given
the opportunity to customize its stored properties further before the
new instance is considered ready for use.
Classes need some kind of default value before the first phase ends. Customising values is part of the second phase.
Objective-C didn’t have this behaviour because it could always give 0
as default for primitives and nil
for objects, but in Swift there is no mechanism to give such a default value.