Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在同一个类中,sampleMethod()从具有弱引用 self() 的闭包中调用方法。self?.sampleMethod()现在使用的 self 的上下文是sampleMethod()什么?是弱者还是强者?
sampleMethod()
self?.sampleMethod()
由于方法sampleMethod()调用成功,self默认情况下它会在它的主体内部使用强引用。
self
你可能会想到这条线
像这样
if let s = self { s.dynamicType.sampleMethod(s)() }
您只需将对实例的强引用传递给相关的类方法