[swift-users] Lazy expression is ambiguous?

Zhao Xin owenzx at gmail.com
Mon Sep 12 02:28:20 CDT 2016

It is not a bug. You must explicitly specify the variable's type if you use
`lazy` keyword. `lazy` means the variable will be initialized later, but
the compiler needs its type right now.


On Mon, Sep 12, 2016 at 3:02 PM, 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.
> Also, you can work around this by adding a type.
>   lazy var myQ: DispatchQueue = DispatchQueue(label: "Op", attributes:
> .concurrent)
> 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 (-:
> Share and Enjoy
> --
> Quinn "The Eskimo!"                    <http://www.apple.com/developer/>
> Apple Developer Relations, Developer Technical Support, Core OS/Hardware
> _______________________________________________
> 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/20160912/fab7e268/attachment.html>

More information about the swift-users mailing list