[swift-users] [swift-evolution] for in? optionalCollection {

Zhao Xin owenzx at gmail.com
Sat Feb 11 06:06:05 CST 2017


What about just use

test?.forEach { print($0) }

Zhaoxin

On Sat, Feb 11, 2017 at 7:48 PM, Tino Heth via swift-evolution <
swift-evolution at swift.org> wrote:

> This one started over at swift-users, with a question on how to deal with
> looping over containers that may be nil.
>
> Imho the beauty of the feature is that it's simple enough to be explained
> in the subject line, but here is the "long" story:
>
> let test: [Int]? = nil
>
> // this is possible now
> if let test = test {
> for i in test {
> print(i)
> }
> }
>
> // how it could be written with a modified keyword
> for i in? test {
> print(i)
> }
>
> I've been thinking "in?" had been brought up long ago, but as I haven't
> found such a proposal, I probably confused it with the cancelled plan to
> write one on my own (or I just was to stupid to search ;-).
>
> Syntactic sugar like this is definitely nothing that has priority now, but
> discussing it shouldn't be a big distraction — and if it turns into a
> proposal that as well survives review, it might be even simple enough to
> act as a trigger for me to finally get my hands on some real work for Swift
> ;-)
>
> - Tino
>
> _______________________________________________
> 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-users/attachments/20170211/f9260992/attachment.html>


More information about the swift-users mailing list