<div dir="ltr"><span style="font-size:12.8px">unsafeUnwrap already exists, though with a slightly different meaning (no check is performed in -O builds).  I think it may be turning into an &quot;unsafelyUnwrapped&quot; property in the future.</span><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Generally I&#39;m +1 on this. I do share others&#39; concerns about things like playgrounds and xibs.</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">I suppose the existence of xibs requires us to keep the ImplicitlyUnwrappedOptional type if we don&#39;t want to require people use &quot;if let&quot; <b>everywhere</b>, unless we somehow move the setting of IBOutlets into a special throwing initializer.</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">For writing quick code in playgrounds, something like &quot;.</span><span style="font-size:12.8px">unsafelyUnwrapped&quot; is probably fine, if a bit wordy. Or if, as Dave Sweeris suggests, you make &quot;unwrap() throws&quot;, then playgrounds can just use &quot;try! x.unwrap()&quot; for unwrapping. (Or did you want to propose removing try! too?)</span></div><div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature"><div dir="ltr"><div>Jacob<br></div></div></div></div>
<br><div class="gmail_quote">On Mon, Feb 29, 2016 at 1:26 PM, Developer via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="auto"><div>I was thinking something more like</div><div><br></div><div>func unsafeUnwrap&lt;T&gt;(opt : Optional&lt;T&gt;) -&gt; T {</div><div>    switch opt {</div><div>        case let .Some(val):</div><div>            return val</div><div>        default:</div><div>             fatalError(&quot;Unexpectedly found nil while unwrapping optional value&quot;)</div><div>    }</div><div>}</div><div><br></div><div>Bang doesn&#39;t go away, it just becomes more obvious that you&#39;re making a leap of logic (as it were).</div><div><br><div>~Robert Widmann</div></div><div><br>2016/02/29 15:59、<a href="mailto:davesweeris@mac.com" target="_blank">davesweeris@mac.com</a> のメッセージ:<br><br></div><div><div class="h5"><blockquote type="cite"><div><div><br></div><blockquote type="cite">On Feb 29, 2016, at 2:24 PM, Developer via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br><br>And for those cases there will be a standard library function or something more obvious than bang to make up for the deprecated operator.  Force unwrapping will not go away (that&#39;s a terribly unproductive idea), but the goal is to make a dangerous operation more obvious[ly dangerous].  <br></blockquote><div><br></div><div>Like this?</div><div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">enum</span><span> OptionalUnwrappingError : </span><span style="color:rgb(112,61,170)">ErrorType</span><span> {</span></div><div style="margin:0px;line-height:normal;font-family:Menlo"><span>    </span><span style="color:rgb(187,44,162)">case</span><span> unexpectedlyFoundNil</span></div><div style="margin:0px;line-height:normal;font-family:Menlo"><span>}</span></div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">enum</span><span> Optional&lt;T&gt; {</span></div><div style="margin:0px;line-height:normal;font-family:Menlo"><span>    </span><span style="color:rgb(187,44,162)">typealias</span><span> Wrapped = </span><span style="color:rgb(112,61,170)">T</span></div><div style="margin:0px;line-height:normal;font-family:Menlo"><span>    </span><span style="color:rgb(187,44,162)">case</span><span> None</span></div><div style="margin:0px;line-height:normal;font-family:Menlo"><span>    </span><span style="color:rgb(187,44,162)">case</span><span> Some(Wrapped)</span></div><div style="margin:0px;line-height:normal;font-family:Menlo">    ...</div><div style="margin:0px;line-height:normal;font-family:Menlo"><span>    </span><span style="color:rgb(187,44,162)">func</span><span> unwrap() </span><span style="color:rgb(187,44,162)">throws</span><span> -&gt; </span><span style="color:rgb(112,61,170)">Wrapped</span><span> {</span></div><div style="margin:0px;line-height:normal;font-family:Menlo"><span>        </span><span style="color:rgb(187,44,162)">switch</span><span> </span><span style="color:rgb(187,44,162)">self</span><span> {</span></div><div style="margin:0px;line-height:normal;font-family:Menlo"><span>        </span><span style="color:rgb(187,44,162)">case</span><span> .None: </span><span style="color:rgb(187,44,162)">throw</span><span> </span><span style="color:rgb(79,129,135)">OptionalError</span><span>.</span><span style="color:rgb(49,89,93)">unexpectedlyFoundNil</span></div><div style="margin:0px;line-height:normal;font-family:Menlo"><span>        </span><span style="color:rgb(187,44,162)">case</span><span> .Some(</span><span style="color:rgb(187,44,162)">let</span><span> value): </span><span style="color:rgb(187,44,162)">return</span><span> value</span></div><div style="margin:0px;line-height:normal;font-family:Menlo"><span>        }</span></div><div style="margin:0px;line-height:normal;font-family:Menlo"><span>    }</span></div><div style="margin:0px;line-height:normal;font-family:Menlo"><span>}</span></div></div><div><span><br></span></div><div><span>It’s hard to get more obvious than the compiler complaining that you haven’t wrapped a throwing function in a try block</span></div><div><span><br></span></div><div><span>- Dave Sweeris</span></div></div></blockquote></div></div></div><br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div></div></div>