【发布时间】:2023-03-17 16:36:01
【问题描述】:
如果我有类似的东西
class Foo {
static shared = Foo()
init() {
print("init Foo")
let _ = Bar.shared
}
}
class Bar {
static shared = Bar()
init() {
print("init Bar")
let _ = Foo.shared
}
}
// somwehere else:
let _ = Foo.shared
然后应用程序卡住了。什么都没发生。我知道这种设计是错误的,但我想知道为什么应用程序没有崩溃、报告错误或至少打印一个循环。以上代码打印
init Foo
init Bar
就是这样,表明它不是循环,而是卡住了。想知道发生了什么?
【问题讨论】:
标签: swift instantiation static-variables