Re: Testing for lazy in Swift
Re: Testing for lazy in Swift
- Subject: Re: Testing for lazy in Swift
- From: Chris Lattner <email@hidden>
- Date: Fri, 11 Jul 2014 12:19:11 -0700
On Jul 11, 2014, at 7:47 AM, Gerriet M. Denkmann <email@hidden> wrote:
>
> @lazy var talker = Talker() // assume Talker takes a lot of time to initialize
>
> if talker == nil
> {
> println("Talker has not been created yet → so it cannot be talking → no need to stop it")}
> return
> }
>
> println("Talker exists → make it shut up")
> taler.stopSpeaking()
>
> This obviously does not work: the test "talker == nil" creates the Talker.
>
> How to avoid this?
There is currently no way to test whether a lazy variable is already initialized or not. We have radars to track this enhancement request, but in the meantime you can emulated it with computed properties. lazy is just syntactic sugar anyway.
-Chris
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden