[swift-evolution] [pre-proposal] Automatic unwrapper boolean properties using unless keyword

Charles Srstka cocoadev at charlessoft.com
Thu Mar 31 18:04:18 CDT 2016


> On Mar 31, 2016, at 5:04 PM, Charles Srstka via swift-evolution <swift-evolution at swift.org> wrote:
> 
> What I often do is use ?? to provide a default (usually false).
> 
> if myList?.isEmpty ?? false {
>     print(“Empty”)
> } else {
>     print(“Not empty”)
> }

That’s what I get for writing a reply quickly; in this particular case the default should probably be true, since you probably want to treat a nil list as empty.

if myList?.isEmpty ?? true {
    print(“Empty”)
} else {
    print(“Not empty”)
}

Charles

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160331/24d2480d/attachment.html>


More information about the swift-evolution mailing list