1

在同一个类中,sampleMethod()从具有弱引用 self() 的闭包中调用方法。self?.sampleMethod()现在使用的 self 的上下文是sampleMethod()什么?是弱者还是强者?

4

1 回答 1

1

由于方法sampleMethod()调用成功,self默认情况下它会在它的主体内部使用强引用。

你可能会想到这条线

self?.sampleMethod()

像这样

if let s = self {
    s.dynamicType.sampleMethod(s)()
}

您只需将对实例的强引用传递给相关的类方法

于 2016-09-13T09:25:41.110 回答