<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
<div class="">Hello community!</div>
<div class=""><br class="">
</div>
<div class="">While writing a Swift introduction tutorial for students, I’ve been stumbling upon the rules for struct default and memberwise initializers.</div>
<div class="">I failed to find explanations in Apple’s language guide, but as far as I could observe, I think the rules don’t fit interesting use-cases.</div>
<div class=""><br class="">
</div>
<div class="">Here are the cases that I was able to identify (I hope you don’t mind millennials and their obligatory Pokemon references):</div>
<div class=""><br class="">
</div>
<div class="">First, as documented in Apple’s guide, structs that doesn’t define any initializer and have no default values receive a memberwise initializer:</div>
<div class=""><br class="">
</div>
<div class="">
<div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(181, 192, 203);" class="">
<div style="margin: 0px; font-size: 11px; line-height: normal; color: rgb(0, 0, 0);" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">typealias</span><span style="font-variant-ligatures: no-common-ligatures" class=""> Species = (number:
</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" class="">, name:
</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">String</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; color: rgb(0, 0, 0); min-height: 13px;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class="">
</div>
<div style="margin: 0px; font-size: 11px; line-height: normal; color: rgb(0, 0, 0);" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">struct</span><span style="font-variant-ligatures: no-common-ligatures" class=""> Pokemon {</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; color: rgb(0, 0, 0);" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> species:
</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Species</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; color: rgb(0, 0, 0);" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> level:
</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Int</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; color: rgb(0, 0, 0);" class="">
<span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);" class="">var</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;nickname:&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);" class="">String</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; color: rgb(0, 0, 0);" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; color: rgb(0, 0, 0); min-height: 13px;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class="">
</div>
<div style="margin: 0px; font-size: 11px; line-height: normal; color: rgb(0, 0, 0);" class="">
<div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> bulby =
</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Pokemon</span><span style="font-variant-ligatures: no-common-ligatures" class="">(species: (001,
</span><span style="font-variant-ligatures: no-common-ligatures; color: #b4261a" class="">&quot;Bulbasaur&quot;</span><span style="font-variant-ligatures: no-common-ligatures" class="">), level: 1, nickname:
</span><span style="font-variant-ligatures: no-common-ligatures; color: #b4261a" class="">&quot;bulby&quot;</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div>
</div>
</div>
</div>
<div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; color: rgb(181, 192, 203);" class="">
<span style="font-variant-ligatures: no-common-ligatures" class=""><br class="">
</span></div>
<div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">Structs that define a default value for all their&nbsp;properties receive a default initializer:</span></div>
<div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><br class="">
</span></div>
<div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">struct</span><span style="font-variant-ligatures: no-common-ligatures" class=""> Pokemon {</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> species:
</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Species</span><span style="font-variant-ligatures: no-common-ligatures" class=""> = (001,
</span><span style="font-variant-ligatures: no-common-ligatures; color: #b4261a" class="">&quot;Bulbasaur&quot;</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> level:
</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" class=""> = 1</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> nickname:
</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">String</span><span style="font-variant-ligatures: no-common-ligatures" class=""> =
</span><span style="font-variant-ligatures: no-common-ligatures; color: #b4261a" class="">&quot;bulby&quot;</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div>
</span></div>
<div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><br class="">
</span></div>
<div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(52, 149, 175);" class="">
<span style="font-variant-ligatures: no-common-ligatures" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);" class="">let</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> bulby&nbsp;<span style="color: rgb(0, 0, 0);" class="">=</span>&nbsp;</span>Pokemon</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">()</span></div>
</span></div>
<div class=""><br class="">
</div>
<div class="">Now digging a bit deeper, I noticed that they also seem to receive an initializer for their non-constant properties:</div>
<div class=""><br class="">
</div>
<div class="">
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> bulby =
</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Pokemon</span><span style="font-variant-ligatures: no-common-ligatures" class="">(level: 1, nickname:
</span><span style="font-variant-ligatures: no-common-ligatures; color: #b4261a" class="">&quot;bulby&quot;</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div>
</div>
<div class=""><span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;" class=""><br class="">
</span></div>
<div class="">If no value is provided for one (or several) of its variable properties, they receives an initializer for all their variable properties:</div>
<div class=""><br class="">
</div>
<div class="">
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">struct</span><span style="font-variant-ligatures: no-common-ligatures" class=""> Pokemon {</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> species:
</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Species</span><span style="font-variant-ligatures: no-common-ligatures" class=""> = (001,
</span><span style="font-variant-ligatures: no-common-ligatures; color: #b4261a" class="">&quot;Bulbasaur&quot;</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> level:
</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" class=""> = 1</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> nickname:
</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">String</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div>
</div>
<div class=""><br class="">
</div>
<div class="">
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> bulby =
</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Pokemon</span><span style="font-variant-ligatures: no-common-ligatures" class="">(level: 1, nickname:
</span><span style="font-variant-ligatures: no-common-ligatures; color: #b4261a" class="">&quot;bulby&quot;</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div>
</div>
<div class=""><br class="">
</div>
<div class="">Finally, if they're given a default value for their variable properties but not for their constant properties, they receive the full memberwise initializer only:</div>
<div class=""><br class="">
</div>
<div class="">
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);" class="">struct</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;Pokemon {</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);" class="">let</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;species:&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);" class="">Species</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);" class="">var</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;level:&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;=
 1</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);" class="">var</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;nickname:&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);" class="">String</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;=&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(180, 38, 26);" class="">&quot;bulby&quot;</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures;" class="">}</span></div>
</div>
<div class=""><br class="">
</div>
<div class="">
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> bulby =
</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Pokemon</span><span style="font-variant-ligatures: no-common-ligatures" class="">(species: (001,
</span><span style="font-variant-ligatures: no-common-ligatures; color: #b4261a" class="">&quot;Bulbasaur&quot;</span><span style="font-variant-ligatures: no-common-ligatures" class="">), level: 1, nickname:
</span><span style="font-variant-ligatures: no-common-ligatures; color: #b4261a" class="">&quot;bulby&quot;</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div>
</div>
<br class="">
<div class="">If the two extreme cases sounds perfectly valid to me (no default value vs all default values), the mixed situations do not.</div>
<div class="">In particular, it seems strange that a struct without a default value for its constant property, but one for all its variable properties receives the memberwise initializer only. I guess that would be a common “mixed situation” case, yet the provided
 initializer is actually useless.</div>
<div class=""><br class="">
</div>
<div class="">Receiving the full memberwise initializer is fine, but I would also expect to receive some kind of &quot;partial memberwise” initializer for all properties (constants or variables) that are not defined:</div>
<div class=""><br class="">
</div>
<div class="">
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);" class="">struct</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;Pokemon {</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);" class="">let</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;species:&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);" class="">Species</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);" class="">var</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;level:&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;=
 1</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);" class="">var</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;nickname:&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);" class="">String</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;=&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(180, 38, 26);" class="">&quot;bulby&quot;</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures;" class="">}</span></div>
</div>
<div class=""><br class="">
</div>
<div class=""><span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);" class="">let</span><span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;" class="">&nbsp;bulby
 =&nbsp;</span><span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);" class="">Pokemon</span><span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;" class="">(species:
 (001,&nbsp;</span><span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures; color: rgb(180, 38, 26);" class="">&quot;Bulbasaur”</span><span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;" class="">)</span><span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;" class="">)</span></div>
<div class="">
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(52, 149, 175);" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">print</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(</span><span style="font-variant-ligatures: no-common-ligatures" class="">bulby</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">)</span></div>
</div>
<div class=""><span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;" class="">
<div style="margin: 0px; line-height: normal; color: rgb(0, 143, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">// Prints &quot;Pokemon(species: (1, &quot;Bulbasaur&quot;), level: 1, nickname: &quot;bulby&quot;)&quot;</span></div>
</span></div>
<div class=""><span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;" class=""><br class="">
</span></div>
<div class="">Besides, that would avoid some tedious initializer definitions. Indeed, If I want to get the desired result, I have to write this kind of initializer:</div>
<div class=""><br class="">
</div>
<div class="">
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">struct</span><span style="font-variant-ligatures: no-common-ligatures" class=""> Pokemon {</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> species:
</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Species</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> level:
</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" class=""> = 1</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> nickname:
</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">String</span><span style="font-variant-ligatures: no-common-ligatures" class=""> =
</span><span style="font-variant-ligatures: no-common-ligatures; color: #b4261a" class="">&quot;bulby&quot;</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class="">
</div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">init</span><span style="font-variant-ligatures: no-common-ligatures" class="">(species:
</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Species</span><span style="font-variant-ligatures: no-common-ligatures" class="">, level:
</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" class="">? =
</span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">nil</span><span style="font-variant-ligatures: no-common-ligatures" class="">, nickname:
</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">String</span><span style="font-variant-ligatures: no-common-ligatures" class="">? =
</span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">nil</span><span style="font-variant-ligatures: no-common-ligatures" class="">) {</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span>
<span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">species</span><span style="font-variant-ligatures: no-common-ligatures" class="">
 = species</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class="">
</div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span>
<span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">if</span><span style="font-variant-ligatures: no-common-ligatures" class=""> level !=
</span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">nil</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>
<span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">level</span><span style="font-variant-ligatures: no-common-ligatures" class="">
 = level!</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class="">
</div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span>
<span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">if</span><span style="font-variant-ligatures: no-common-ligatures" class=""> nickname !=
</span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">nil</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>
<span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">nickname</span><span style="font-variant-ligatures: no-common-ligatures" class="">
 = nickname!</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; }</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div>
</div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class=""><br class="">
</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-family: Helvetica; font-size: 12px;" class="">In addition to be rather wordy, it arguably destroys the purpose of defining a default value for variable properties in the first place, since imho this approach is clearer (unless maybe for some
 more complicated structs with multiple layers of initializer delegation):</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-family: Helvetica; font-size: 12px;" class=""><br class="">
</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<div style="margin: 0px; line-height: normal;" class="">
<div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">struct</span><span style="font-variant-ligatures: no-common-ligatures" class=""> Pokemon {</span></div>
<div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp;
</span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> species:
</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Species</span></div>
<div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp;
</span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> level:
</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Int</span></div>
<div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp;
</span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> nickname:
</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">String</span></div>
<div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class="">
</div>
<div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp;
</span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">init</span><span style="font-variant-ligatures: no-common-ligatures" class="">(species:
</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Species</span><span style="font-variant-ligatures: no-common-ligatures" class="">, level:
</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" class=""> = 1, nickname:
</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">String</span><span style="font-variant-ligatures: no-common-ligatures" class=""> =
</span><span style="font-variant-ligatures: no-common-ligatures; color: #b4261a" class="">&quot;bulby&quot;</span><span style="font-variant-ligatures: no-common-ligatures" class="">) {</span></div>
<div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp;
</span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">species</span><span style="font-variant-ligatures: no-common-ligatures" class="">
 = species</span></div>
<div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp;
</span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">level</span><span style="font-variant-ligatures: no-common-ligatures" class="">
 = level</span></div>
<div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp;
</span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">nickname</span><span style="font-variant-ligatures: no-common-ligatures" class="">
 = nickname</span></div>
<div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; }</span></div>
<div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div>
<div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class="">
</span></div>
<div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span style="font-family: Helvetica; font-size: 12px;" class="">Thanks.</span></span></div>
<div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span style="font-family: Helvetica; font-size: 12px;" class=""><br class="">
</span></span></div>
<div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span style="font-family: Helvetica; font-size: 12px;" class="">Dimitri Racordon</span></span></div>
<div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span style="font-family: Helvetica; font-size: 12px;" class=""><br class="">
</span></span></div>
</div>
</div>
</body>
</html>