mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
58 lines
849 B
Plaintext
58 lines
849 B
Plaintext
func test1() {
|
|
if true {
|
|
let x = 1
|
|
print(x)
|
|
} else {
|
|
let x = 2
|
|
print(x)
|
|
}
|
|
}
|
|
|
|
func test2(arg1: Int?, arg2: (Int, String)?) {
|
|
if let x = arg1 {
|
|
print(x)
|
|
} else if let (x, y) = arg2 {
|
|
print(x, y)
|
|
}
|
|
}
|
|
|
|
func test3(arg: Int?) {
|
|
switch arg {
|
|
case let .some(x) where x == 0:
|
|
print(x)
|
|
case let .some(x) where x == 1,
|
|
let .some(x) where x == 2:
|
|
print(x)
|
|
fallthrough
|
|
case let .some(x) where x == 3:
|
|
print(x)
|
|
default:
|
|
break
|
|
}
|
|
}
|
|
|
|
struct Err1 : Error { }
|
|
func test4(arg: () throws -> Void) {
|
|
do {
|
|
try arg()
|
|
} catch let x as Err1 {
|
|
print(x)
|
|
} catch let x {
|
|
print(x)
|
|
}
|
|
}
|
|
|
|
func test5(_ <base>x</base>: Int) {
|
|
let x = <base>x</base>
|
|
print(x)
|
|
}
|
|
|
|
func testCaptureVariable() {
|
|
let capturedVariable = 0
|
|
|
|
_ = { [capturedVariable] in
|
|
print(capturedVariable)
|
|
}
|
|
}
|
|
|