[swift-users] for in? optionalCollection {
Tino Heth
2th at gmx.de
Sat Feb 11 05:48:54 CST 2017
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170211/69eb4a20/attachment.html>
More information about the swift-users
mailing list