Re: Possible to defer initialization of let variable?
Re: Possible to defer initialization of let variable?
- Subject: Re: Possible to defer initialization of let variable?
- From: Rick Mann <email@hidden>
- Date: Tue, 07 Jul 2015 01:39:17 -0700
> On Jul 7, 2015, at 01:37 , Quincey Morris <email@hidden> wrote:
>
> On Jul 7, 2015, at 01:33 , Rick Mann <email@hidden> wrote:
>>
>> Yeah, there doesn't seem to be an elegant way to do it
>
> Actually, there is:
>
>> let thumbURL: String? =
>> {
>> for imgD in images
>> {
>> if let isHero = imgD["is_hero"] as? Bool where isHero,
>> let t = imgD["thumbnail_signed_src"] as? String
>> {
>> return t
>> }
>> }
>>
>> return nil
>> } ()
>
> Or, if you prefer, instead of using a closure, you can define a nested function and call it to get the initial value.
I tried it as a closure. The problem arises when you want to initialize more than one variable in that block of work.
--
Rick Mann
email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden