> On 12 Jun 2015, at 08:49, Roland King <r...@rols.org> wrote:
> 
> Trying out some of the new Swift 2 features for pattern matching (What’s New 
> In Swift around the 19m 35s + mark with Chris Lattner) but not having much 
> success. I have this in a playground
> 
>       enum test
>       {
>               case one
>               case two( Int )
>               case three( String, Int )
>       }
> 
>       let x = [ test.one, test.two( 123 ), test.three( "xx", 1 ), test.one, 
> test.three( "rrr", 7 ), test.two( 9 ) ]
> 
>       for case test.two( let a ) in x
>       {
>               print( "a is \(a) " )
>       }
> 
> Which follows the pattern shown on-screen, as I understand it at least, and 
> in the updated Swift beta 2 book
> 
> I get numerous errors on the ‘for case .’ line, the compiler clearly thinks 
> the entire line is garbage. I’ve tried taking the ‘case’ word out, that 
> doesn’t work, I’ve tried taking the ‘test.’ off the start of ‘test.two’, 
> still no good, possibly worse.
> 
> Tried a simple version in an if as well 
> 
>       let y = test.two( 123 )
> 
> 
>       if case test.two( let a ) == y {  }             // variable binding in 
> a condition requires an initializer
> 
> 
> I must have tried 10 other combinations as well without any success. I must 
> have entirely misunderstood the new uniform case pattern matching, or it 
> doesn’t work in seed 1. The ‘if case’ construct is going to be quite useful, 
> anyone else have more success? 

I can answer the second half of my own question

        let y = test.two( 123 )

        if case test.two( let a ) = y {}

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. 




_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to