var things = Any[]()
things.append(0)
things.append(0.0)
things.append(42)
things.append(3.14159)
things.append("hello")
things.append((3.0, 5.0))
things.append(Movie(name:"Ghostbusters", director:"Ivan Reitman"))
for thing in things {
switch thing {
case 0 as Int:
println("zero as an Int")
case 0 as Double:
println("zero as a Double")
case let someInt as Int:
println("an integer value of (someInt)")
case let someDouble as Double where someDouble > 0:
println("a positive double value of (someDouble)")
case is Double:
println("some other double value that I don't want to print")
case let someString as String:
println("a string value of "(someString)"")
case let (x, y) as (Double, Double):
println("an (x, y) point at (x), (y)")
case let movie as Movie:
println("a movie called '(movie.name)', dir. (movie.director)")
default:
println("something else")
}
}
// zero as an Int
// zero as a Double
// an integer value of 42
// a positive double value of 3.14159
// a string value of"hello"
// an (x, y) point at 3.0, 5.0
// a movie called 'Ghostbusters', dir. Ivan Reitman
class A {
}
var o = A()
var o1 = A()
var o2 = A()
switch o {
case o1:
print("it is o1")
case o2:
print("it is o2")
default:
print("not o1 or o2")
}
switch o {
case let o1:
print("it is o1")
case let o2:
print("it is o2")
default:
print("not o1 or o2")
}
class A {}
func == (lhs: A, rhs: A) -> Bool { return true }
var o = A(); var o1 = A() ;var o2 = A()
switch o {
case o1:
print("it is o1")
case o2:
print("it is o2")
default:
print("not o1 or o2")
}
@warn_unused_result public func ~=<T : Equatable>(a: T, b: T) -> Bool
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有