<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 "unsafelyUnwrapped" property in the future.</span><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Generally I'm +1 on this. I do share others' 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't want to require people use "if let" <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 ".</span><span style="font-size:12.8px">unsafelyUnwrapped" is probably fine, if a bit wordy. Or if, as Dave Sweeris suggests, you make "unwrap() throws", then playgrounds can just use "try! x.unwrap()" 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"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></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<T>(opt : Optional<T>) -> T {</div><div> switch opt {</div><div> case let .Some(val):</div><div> return val</div><div> default:</div><div> fatalError("Unexpectedly found nil while unwrapping optional value")</div><div> }</div><div>}</div><div><br></div><div>Bang doesn't go away, it just becomes more obvious that you'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 <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> 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'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<T> {</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> -> </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>