[swift-evolution] Guard let

Gmail david.ronnqvist at gmail.com
Mon Jun 12 11:19:24 CDT 2017


Yes, this is the proper channel to discuss this kind of proposal. 

What you’re proposing has been brought up before, or as Chris Lattner put it:
“Yes, this has thoroughly been beaten to death. It is also outside the scope of Swift 4 stage 1. That said, it is such a glaring problem that we’ll have to deal with it at some point.”
https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20161024/028448.html <https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20161024/028448.html>

I don’t recall if there was a conclusion other than that it was out of scope.

This message from 26 October 2016 seems to be the start of the longest discussion of it that I could find: 
https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20161024/028440.html <https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20161024/028440.html>

Also, Erica Sadun drafted a proposal for it:
https://gist.github.com/erica/db9ce92b3d23cb20799460f603c0ae7c <https://gist.github.com/erica/db9ce92b3d23cb20799460f603c0ae7c>

Unfortunately, given how close to release it is, I would guess that it’s still out of scope for Swift 4. 
If it’s out of scope, Ted Kremenek very recently gave some input on “Swift phases and mis-timed proposals”:
https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20170612/037340.html <https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20170612/037340.html>

Regards,
David


> On 10 Jun 2017, at 06:07, Justin Oroz via swift-evolution <swift-evolution at swift.org> wrote:
> 
> First time trying to contribute, hopefully this is the proper channel to submit.
> 
> I propose an addition to the guard let statement to allow for replacement of optionals with unwrapped values.
> 
> ex)
> 
> two current options
> 
> 
> obj.methodWithCallback() {(foo, bar) in
> 	guard let foo = foo else { 
> 		return
> 	}
> 	
> 	foo.prop = “new”
> }
> 
> OR
> 
> obj.methodWithCallback() {(foo, bar) in
> 	guard foo != nil else { 
> 		return
> 	}
> 	
> 	foo!.prop = “new”
> }
> 
> 
> I propose the following option:
> 
> obj.methodWithCallback() {(foo, bar) in
> 	guard foo else { 
> 		return
> 	}
> 	
> 	foo.prop = “new”
> }
> 
> This reduces the seemingly redundant "guard let foo = foo” statement and removes the unnecessary forced optional unwrapping. 
> 
> - Justin
> 
> 
> _______________________________________________
> 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/20170612/1e83c299/attachment.html>


More information about the swift-evolution mailing list