• 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: for case and if case (Swift 2)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: for case and if case (Swift 2)


  • Subject: Re: for case and if case (Swift 2)
  • From: Marco S Hyman <email@hidden>
  • Date: Thu, 11 Jun 2015 19:48:16 -0700

>> yes ‘=‘ instead of ‘==‘. I hit on that trying random things and don’t really understand it, an ‘=‘ in an if() test is something I’m having trouble getting my brain around.
>
> It’s not that strange. The statement contains an initializer (conceptually 'let a = y.assocatedValue’), so there’s gonna be a “=“. Note that in your original version:
>
>> if case test.two( let a ) == y {  }
>
> what’s on the LHS of the “==“ isn’t a value of any kind — what were you expecting the value of ‘a’ to be?

"You extract each associated value as a constant (with the let prefix) or a variable (with the var prefix) for use within the switch case’s body...”

Given that I’d expect if case to act as if I’d done roughly the same thing
with a switch statement

switch test {
    case .two(let a)
	// do something with .two’s associated value
    default:
	// do something else
}


Marc
_______________________________________________

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


  • Follow-Ups:
    • Re: for case and if case (Swift 2)
      • From: Quincey Morris <email@hidden>
References: 
 >for case and if case (Swift 2) (From: Roland King <email@hidden>)
 >Re: for case and if case (Swift 2) (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: for case and if case (Swift 2)
  • Next by Date: Re: for case and if case (Swift 2)
  • Previous by thread: Re: for case and if case (Swift 2)
  • Next by thread: Re: for case and if case (Swift 2)
  • Index(es):
    • Date
    • Thread