Example:
class A {
var fn: (() -> ())? = nil
}
class B {
let a = A()
init() {
a.fn = someFn
}
func someFn() {
}
}
Now we have cyclic reference, because B owns A by direct ref a and A implicitly owns B by self owned in fn closure (correct me if I'm wrong).
Possible solutions is:
weak var fn is not good for my case because I'm assigning not only methods.'weak' may only be applied to class and class-bound protocol types.a.fn = { [unowned self] in self.someFn() }is correct solution, but too verbose.
Is there any other solutions?