Define a tuple
Let color = (1.0,1.0,1.0,1.0)
Switch color{
Case (0.0,0.5...1.0,let blue,_)://Match the first value is 0.0 the second value is 0.5 to 1.0 the 34th value is arbitrary, and the third value is passed to the blue variable
println ("Blue Is \ (blue)")
Case let (r,g,b,1.0) where r = = g && g = = B://Additional conditions where this one is also the value is equal
println ("Opaque grey \ (r * 100)%")
Default
println ("Unkonw")
}
Ganso is done, then define a struct.
struct Color {
var red:double?
var green:double?
var blue:double?
var alpha:double?
Init (red:double,green:double,blue:double,alpha:double) {
self.red = Red
Self.green = Green
Self.blue = Blue
Self.alpha = Alpha
}
}
var mycolor = Color (Red:10, green:20, blue:60, alpha:1.0)
Switch mycolor{
Case let a where a.red = = && A.blue = = 60:
println ("yes")
Default
println ("Unkonw")
}
SWIFT Tuple pattern and struct pattern