所以我有以下结构并且很好奇这是否可能。
class Chip8
{
let foo = 10;
let mapping = [
// CLS (clear the display)
0x00E0: { (argument: Int) -> Void in
// How can I reach self.foo here (self.foo obviously does not work, which is the premise of the question)
},
]
}
这样的事情可能吗?
编辑:
似乎如果我将映射的初始化移动到构造函数,我就可以访问“self”
最佳答案
你也可以试试
class Chip8
{
let foo = 10;
lazy var mapping:[Int: (Int)->Void] = {
return [
// CLS (clear the display)
0x00E0: { (argument: Int) -> Void in
// How can I reach self.foo here (self.foo obviously does not work, which is the premise of the question)
self.foo
},
]
}()
}
关于ios - 在类中定义的闭包中到达 "self",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32120812/