Was using relamquad's answer quite successfully until I noticed it can lead to memory leaks due to strong reference cycles.
Using it like described works fine:
Swift
var body: some View {
SomeView().uiKitOnAppear {
print("I am uiKitAppear")
}
}
However if you pass a ViewModel's function for example, the ViewModel will not be deallocated once the View should be deinitialized:
Swift
@ObservedObject var viewModel: ViewModel
var body: some View {
SomeView().uiKitOnAppear {
viewModel.startUpdating()
}
}
If been trying to find a solution using weak references, but then again, somehow startUpdating is not called on .uiKitOnAppear().
Does anybody know a solution to this?
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: