[swift-evolution] Proposal: Add implicit/default else-behaviour for the guard statement
Andrew Bennett
cacoyi at gmail.com
Thu Dec 17 05:20:38 CST 2015
I'm a +1 on the return defaults with void/optional.
Within a switch I'm on the fence, it seems reasonable to break, but you may
want to return.
Within a loop I'm against it, I think I think that continue makes the most
sense (forEach will exhibit the same behaviour), but you may want break or
return.
On Thu, Dec 17, 2015 at 10:01 PM, Gwendal Roué <swift-evolution at swift.org>
wrote:
>
> > Le 17 déc. 2015 à 11:58, Andrey Tarantsov via swift-evolution <
> swift-evolution at swift.org> a écrit :
> >
> > 4) I would love a “guard!” variant that crashes instead of returning.
>
> Isn’t it the role of assert and precondition?
>
> Yet I have to admit that assert and precondition can not replace guards
> like the following, which define a variable:
>
> guard let x = optionalX else {
> fatalError("Missing x")
> }
> // use x
>
> Gwendal Roué
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151217/03b1c72e/attachment.html>
More information about the swift-evolution
mailing list