I decided to play with Swift and tuple statements. It looks like one of the more complex language features.
I decided to play with the tuples month / day / year. To my surprise, I cannot use the constant value of a tuple as a case in a switch statement. Here is an example (you can insert into the playing field and run)
import UIKit
typealias mdyTuple = (month: Int, day: Int, year: Int)
let joesBirthday: mdyTuple = (month: 6, day: 7, year: 1978)
let someday: mdyTuple = (6, 7, 1978)
switch someday
{
case (joesBirthday.month, joesBirthday.day, joesBirthday.year):
println("Joe was born on this day")
case (joesBirthday.month, joesBirthday.day, let year):
println("Joe is \(year-joesBirthday.year) today")
default:
println("Some other day")
}
Commented code case joesBirthday:will not compile (in Xcode 6.3, if that matters). The following case (where I list all the elements of the joesBirthday tuple separately), which is harder to enter and harder to read, works)
My playground crashed Xcode when I typed this message and AGAIN worked, trying to restart Xcode, so I can not report the error code.
, , , Xcode, ( 4 . Yayyy!) : " ~= mdyTuple."
~=? ?
, switch?