//There is no static initialization block in Swift.
//A stored type property is initialized lazily, on
//the first access, and only once - even when
//several threads reach it at the same time.
class Config {
static let table: [String: Int] = {
print("the block runs on first access")
return ["a": 1, "b": 2]
}()
//An instance is set up in init()
var name: String
init() {
name = "config"
}
}
print("before the first access")
let a = Config.table["a"]!
//a is 1
print("a is \(a)")
//The block does not run a second time
let b = Config.table["b"]!
//b is 2
print("b is \(b)")