let a: Int? = Int("2") let b: Int? = Int("x") let sum: Int? = a.flatMap { a in b.map { b in a + b } } print(sum as Any)
guard let a = Int("2") else { // エラーハンドリング } print(a + 1)
var stack = [2, 3, 5] print(stack.popLast() as Any) print(stack.popLast() as Any) print(stack.popLast() as Any) print(stack.popLast() as Any) var queue: ArraySlice<Int> = [2, 3, 5] print(queue.popFirst() as Any) print(queue.popFirst() as Any) print(queue.popFirst() as Any) print(queue.popFirst() as Any)
let array: [Int] = [2, 3, 5, 7, 11] let slice: ArraySlice<Int> = array[...] print(slice)
// Recoverable errors do { try foo() } catch { // エラーハンドリング }