|
import Foundation
|
|
|
|
// Unicode comment: δ½ ε₯½δΈη ππ
|
|
|
|
// Unicode string literals
|
|
let unicode = "γγγ«γ‘γ―δΈη"
|
|
print(unicode)
|
|
|
|
// Null byte in string
|
|
let nullStr = "hello\0world"
|
|
print("Null-str length: \(nullStr.count)")
|
|
|
|
// Deeply nested optionals
|
|
let deep: Int????? = 42
|
|
if let l1 = deep,
|
|
let l2 = l1,
|
|
let l3 = l2,
|
|
let l4 = l3 {
|
|
print("Deep optional: \(l4)")
|
|
}
|
|
|
|
// Very long string
|
|
let longStr = String(repeating: "x", count: 10000)
|
|
print("Long string length: \(longStr.count)")
|
|
|
|
// BOM bytes
|
|
let bom = Data([0xEF, 0xBB, 0xBF, 0x48, 0x69])
|
|
print(String(data: bom, encoding: .utf8) ?? "")
|
|
|
|
// Deep closure nesting
|
|
let f1: (Int) -> (Int) -> (Int) -> (Int) -> Int = { x in
|
|
{ y in
|
|
{ z in
|
|
{ w in x + y + z + w }
|
|
}
|
|
}
|
|
}
|
|
print("Nested closures: \(f1(1)(2)(3)(4))")
|
|
|
|
// Deep dictionary nesting
|
|
let deepDict: [String: Any] = [
|
|
"a": [
|
|
"b": [
|
|
"c": [
|
|
"d": [
|
|
"e": "deep"
|
|
]
|
|
]
|
|
]
|
|
]
|
|
]
|
|
if let a = deepDict["a"] as? [String: Any],
|
|
let b = a["b"] as? [String: Any],
|
|
let c = b["c"] as? [String: Any],
|
|
let d = c["d"] as? [String: Any],
|
|
let e = d["e"] as? String {
|
|
print("Deep dict: \(e)")
|
|
}
|
|
|
|
// Deep error nesting
|
|
enum AppError: Error {
|
|
case inner(String)
|
|
case middle(String, Error)
|
|
case outer(String, Error)
|
|
}
|
|
|
|
do {
|
|
do {
|
|
do {
|
|
throw AppError.inner("oops")
|
|
} catch {
|
|
throw AppError.middle("wrapped", error)
|
|
}
|
|
} catch {
|
|
throw AppError.outer("re-wrapped", error)
|
|
}
|
|
} catch {
|
|
print("Nested error: \(error)")
|
|
}
|