Re: Testing for lazy in Swift
Re: Testing for lazy in Swift
- Subject: Re: Testing for lazy in Swift
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Fri, 11 Jul 2014 23:27:41 +0700
On 11 Jul 2014, at 22:53, Jeremy Pereira <email@hidden> wrote:
> Have the function Talker() record the fact that it has created the instance variable in a boolean.
>
> Or if you don't want to change Talker() use a closure to set the boolean and run Talker.
>
Two very good ideas. Thanks a lot!
Kind regards
Gerriet
> On 11 Jul 2014, at 15:47, 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?
_______________________________________________
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