-
senseclass MyAVC: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// register `self` to `container`, and `weak` store it
}
} then
but i did not find register instance directly func in factory |
Beta Was this translation helpful? Give feedback.
Answered by
hmlongco
Dec 29, 2024
Replies: 2 comments
-
The factory must exist. If you have to do this, I'd consider... internal struct WeakObject<T: AnyObject> {
weak var object: T?
}
extension Container {
var referenceMyAVC: Factory<WeakObject<MyAVC>> {
self { .init(object: nil) }
}
}
class MyAVC: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
Container.shared.referenceMyAVC.register { .init(object: self) }
}
}
class MyDVC: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
weak var myAVC = Container.shared.referenceMyAVC.resolve().object
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
faimin
-
copy that, thank you. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The factory must exist. If you have to do this, I'd consider...