[swift-users] Lazy expression is ambiguous?

Rick Mann rmann at latencyzero.com
Mon Sep 12 02:46:48 CDT 2016

> On Sep 12, 2016, at 00:02 , Quinn The Eskimo! via swift-users <swift-users at swift.org> wrote:
> On 12 Sep 2016, at 06:40, Jacob Bandes-Storch via swift-users <swift-users at swift.org> wrote:
>> I'd recommend filing a bug at bugs.swift.org.
> Agreed.

Done. https://bugs.swift.org/browse/SR-2616

> Also, you can work around this by adding a type.
>  lazy var myQ: DispatchQueue = DispatchQueue(label: "Op", attributes: .concurrent)

Sure, it just didn't seem to make sense.

> Also, with regards this specific example, be aware that lazy properties aren’t guaranteed to be initialised only once.  To quote “The Swift Programming Language”:
>    If a property marked with the `lazy` modified is accessed by multiple 
>    threads simultaneously and the property has not yet been initialized, 
>    there is no guarantee that the property will be initialized only once.
> I’m struggling to think of a case where that limitation is acceptable in the context of a dispatch queue (-:

Thank you for that explanation. I had assumed lazy worked like static, which I understand uses dispatch_once under the hood. Would that be a reasonable thing for lazy to do?

In the end I didn't use a property for the queue, but rather just created it at point of use (I'm testing to see whether or not the enqueued blocks retain the queue; that's all I need).

Rick Mann
rmann at latencyzero.com

More information about the swift-users mailing list