[swift-users] Nil coalescing operator and closures
davesweeris at mac.com
davesweeris at mac.com
Wed Feb 24 08:11:39 CST 2016
Assuming you've merely omitted the code where you set closure to something and aren’t trying to read a variable before initializing it, I believe it's a bug... Using the "explicit" version works fine:
let closure: Closure? = nil
let otherClosure: Closure = {}
let pickClosure = closure != nil ? closure! : otherClosure
- Dave Sweeris
> On Feb 24, 2016, at 7:37 AM, Rudolf Adamkovič via swift-users <swift-users at swift.org> wrote:
>
> Hello there!
>
> Today, I stumbled upon the following error:
>
> typealias ClosureType = () -> Void
>
> let closure: ClosureType?
> let otherClosure: ClosureType = {}
>
> let pickClosure = closure ?? otherClosure
> // ERROR: binary operator '??' cannot be applied to operands of type 'ClosureType?' and 'ClosureType' (aka '() -> ()')
>
> Is this a bug or a feature?
>
> Thanks!
>
> Rudolf Adamkovic
> R+
>
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160224/af4d24c3/attachment.html>
More information about the swift-users
mailing list