Re: Simple Swift question
Re: Simple Swift question
- Subject: Re: Simple Swift question
- From: Charles Srstka <email@hidden>
- Date: Mon, 29 Jun 2015 18:10:05 -0500
On Jun 29, 2015, at 5:53 PM, Rick Mann <email@hidden> wrote:
>
>> If you are using Swift 2.0, you can use the new `guard let` to get optional checking without the cascade of indentation.
>> guard let url = NSURL(string: "<some url>")
>> else { /* handle failure and either halt or return */ }
>> // URL is now in scope and non-optional.
>> let req = NSURLRequest(URL: url)
>
> I am, but this may not work as well if there are additional steps after this one that should run anyway. Can I enclose the bit in braces to limit the scope of the break? Probably not, huh? e.g.:
>
> {
> guard let url = ... else { break }
> <use url>
> }
>
> {
> ...other init...
> }
Look into the “defer” keyword.
Charles
_______________________________________________
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