<div dir="ltr">Im curious to know the reasoning behind why implicit-wrapped optionals aren't allowed when creating tuples. Below is an example with type aliases and anonymous tuples.<div><div><br></div><div>ex. </div><div><p style="margin:0px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(195,34,117)">typealias</span><span style="font-variant-ligatures:no-common-ligatures"> Name = (first: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">String</span><span style="font-variant-ligatures:no-common-ligatures">!, middle: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">String</span><span style="font-variant-ligatures:no-common-ligatures">?, last: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">String</span><span style="font-variant-ligatures:no-common-ligatures">!)</span></p></div><div><span style="font-variant-ligatures:no-common-ligatures"><div><p style="margin:0px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(195,34,117)">typealias</span><span style="font-variant-ligatures:no-common-ligatures"> Name = (first: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">String</span><span style="font-variant-ligatures:no-common-ligatures">!, middle: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">String</span><span style="font-variant-ligatures:no-common-ligatures">?, last: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">String</span><span style="font-variant-ligatures:no-common-ligatures">!)!</span></p><p style="margin:0px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures"><span style="color:rgb(195,34,117)">var</span> name : (</span><span style="font-variant-ligatures:no-common-ligatures">first: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">String</span><span style="font-variant-ligatures:no-common-ligatures">!, middle: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">String</span><span style="font-variant-ligatures:no-common-ligatures">?, last: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">String</span><span style="font-variant-ligatures:no-common-ligatures">!</span>)</p></div><div><span style="font-variant-ligatures:no-common-ligatures"><span style="font-family:menlo;font-variant-ligatures:no-common-ligatures"><font color="#c32275">var </font>name : (first: </span><span style="font-family:menlo;font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">String</span><span style="font-family:menlo;font-variant-ligatures:no-common-ligatures">!, middle: </span><span style="font-family:menlo;font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">String</span><span style="font-family:menlo;font-variant-ligatures:no-common-ligatures">?, last: </span><span style="font-family:menlo;font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">String</span><span style="font-family:menlo;font-variant-ligatures:no-common-ligatures">!)!</span><br></span></div><div><span style="font-variant-ligatures:no-common-ligatures"><span style="font-family:menlo;font-variant-ligatures:no-common-ligatures"><br></span></span></div><div><span style="font-variant-ligatures:no-common-ligatures">error from all 4 examples above:</span></div><div><span style="font-variant-ligatures:no-common-ligatures">Implicitly unwrapped optionals are only allowed at top level and as function results</span></div><div><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div><span style="font-variant-ligatures:no-common-ligatures">I also noticed that I can modify tuples using functions ONLY if I use <b>inout</b>. </span></div><div><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div><span style="font-variant-ligatures:no-common-ligatures"><span style="font-variant-ligatures:no-common-ligatures"><p style="margin:0px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(195,34,117)">func</span><span style="font-variant-ligatures:no-common-ligatures"> name(Person : </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(195,34,117)">inout</span><span style="font-variant-ligatures:no-common-ligatures"> (first: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">String</span><span style="font-variant-ligatures:no-common-ligatures">?, middle: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">String</span><span style="font-variant-ligatures:no-common-ligatures">?, last: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)">String</span><span style="font-variant-ligatures:no-common-ligatures">?)) {</span></p><p style="margin:0px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures"> Person.first = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(201,27,19)">"John"</span></p><p style="margin:0px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures"> Person.last = </span><span style="color:rgb(201,27,19)">"Doe"</span></p><p style="margin:0px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">}</span></p><p style="margin:0px;line-height:normal;font-family:menlo"><br></p><p style="margin:0px;line-height:normal;font-family:menlo">OR </p><p style="margin:0px;line-height:normal;font-family:menlo"><br></p><p style="margin:0px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(195,34,117)">func</span><span style="font-variant-ligatures:no-common-ligatures"> name(Person : </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(195,34,117)">inout</span><span style="font-variant-ligatures:no-common-ligatures"> Name</span><span style="font-variant-ligatures:no-common-ligatures">) {</span></p><p style="margin:0px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures"> Person.first = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(201,27,19)">"John"</span></p><p style="margin:0px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures"> Person.last = </span><span style="color:rgb(201,27,19)">"Doe"</span></p><p style="margin:0px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures"></span></p><p style="margin:0px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures">}</span></p><div><br></div><div>This is because tuples are passed into functions as 'let' constants. Why not add the ability to modify a copy of the tuple inside the function ?</div><div><br></div></span></span></div></span></div><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr">Best Regards,<div><br></div><div>Muhammad T. Vali</div></div></div>
</div></div>