Besides using unowned instead of weak, what can be done in order to guarantee that the reference passed to the constructor is not created during constructor invocation?
Namely, if the class has a weak reference/unowned reference member - We wouldn’t want to allows things like
class MyClass {
unowned let someMember: MemberClass
...
init(someMemeber: MemberClass) {
self.someMember = someMember
}
}
let classInstance = MyClass(someMember: MemberClass(...) )
In this case - expect a nice dangling reference error - (unowned references are particularly bad - weak references at least check for null - but we still have same problem - there is no guarantee that the class doesn’t actually own this reference).
What is the proper way to enforce it? On one hand, seems that inout parameters in the constructor solve this… On the other hand - we can not pass parameters declared as “let” this way…
An addition to the tutorial describing how to handle this would be greatly appreciated