• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Simple Swift question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Simple Swift question (From: Rick Mann <email@hidden>)
 >Re: Simple Swift question (From: Greg Parker <email@hidden>)
 >Re: Simple Swift question (From: Rick Mann <email@hidden>)

  • Prev by Date: Re: Swift and parameter names
  • Next by Date: Re: Swift and parameter names
  • Previous by thread: Re: Simple Swift question
  • Next by thread: Re: Simple Swift question
  • Index(es):
    • Date
    • Thread