我正在尝试创建一个包含对self或其他对象的引用的对象类:
class MyObject
{
let owner: MyObject
init(owner: MyObject) {
self.owner = owner;
}
}
class RootObject : MyObject
{
init() {
self.owner = self
}
}
var root = RootObject()
var child = MyObject(root)
// child.owner == root
// child.owner.owner == root
是否可以在不使用选项的情况下修改此代码并实现我的想法?