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

for case and if case (Swift 2)


  • Subject: for case and if case (Swift 2)
  • From: Roland King <email@hidden>
  • Date: Fri, 12 Jun 2015 08:49:44 +0800

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?
_______________________________________________

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>
    • Re: for case and if case (Swift 2)
      • From: Quincey Morris <email@hidden>
    • Re: for case and if case (Swift 2)
      • From: Roland King <email@hidden>
  • Prev by Date: 3D file formats
  • Next by Date: Re: for case and if case (Swift 2)
  • Previous by thread: Re: 3D file formats
  • Next by thread: Re: for case and if case (Swift 2)
  • Index(es):
    • Date
    • Thread