Re: Can I show different content in different screens? (screensaver)
Re: Can I show different content in different screens? (screensaver)
- Subject: Re: Can I show different content in different screens? (screensaver)
- From: Greg Parker <email@hidden>
- Date: Fri, 24 Jul 2015 19:43:55 -0700
> On Jul 24, 2015, at 7:19 PM, Roland King <email@hidden> wrote:
>
> if let screen = window?.screen
> {
> find(…)
> }
> else
> {
> // handle the lack of a screen gracefully
> }
>
> it’s longer, but it’s clearer and it says I’ve considered what semantically it means to have a nil screen.
You may prefer the new `guard let` construct for this pattern.
> PS does anyone know (in swift 2.0) of a way to use the ternery operator with let/case so you can initialise a variable without curly braces everywhere, I want to write
>
> let myVar = ( let ifNotOptional = something?.something else ) ? ifNotOptional.stringName : “No Name”
>
> but can’t find any syntax to do something like that
You can separate the let declaration from the initialization, as long as the compiler can see that it is assigned exactly once before it is used along all code paths. The compiler recently became smarter at this analysis so it works in more cases. (Downside: you must specify the variable's type.)
let myVar: String
if let value = something?.somethingElse {
myVar = value.stringName
} else {
myVar = "No Name"
}
--
Greg Parker email@hidden Runtime Wrangler
_______________________________________________
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