<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div></div><div><br></div><div>Am 16.02.2016 um 05:52 schrieb Paul Ossenbruggen via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>>:<br><br></div><blockquote type="cite"><div>I guess if auto closure could take a parameter you could do something like this:</div><div><br class=""></div><div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);" class="">@warn_unused_result</div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">public</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> ??<T>(optional: T?, <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">@autoclosure</span> defaultValue: (result : T) <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">throws</span> -> T) <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">rethrows</span> -> <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">T</span> {</div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span> optional != <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">nil</span> ? optional! : <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">try</span> defaultValue(result: optional!)</div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class="">}</div></div></blockquote><br><div>This will always throw an exception as you are force unwrapping the optional in both branches of the ternary, i.e. also in the branch which is used when it is nil.</div><div><br></div><div>-Thorsten </div></body></html>