Lately I noticed a difficulty in SwiftUI and broke it right down to this code for demonstration functions:
import SwiftUI
// Mother or father view
struct ContentView: View {
@State var overlayVisible: Bool = false
var physique: some View {
VStack {
Button("Present") {
withAnimation {
overlayVisible = true
}
}
.overlay {
if overlayVisible {
ChildView(onHide: {
withAnimation {
overlayVisible = false
}
})
.transition(.transfer(edge: .backside))
}
}
}
.padding()
}
}
// Youngster view + @StateObject
class ChildViewStore: ObservableObject {
@Revealed var alertVisible: Bool = false
}
struct ChildView: View {
@Setting(.presentationMode) var presentationMode
@StateObject var retailer: ChildViewStore = ChildViewStore()
var onHide: (() -> Void)?
var physique: some View {
Coloration.grey
.ignoresSafeArea(.all) // Ignore only for the colour
.overlay{
VStack {
Button("Dismiss") {
presentationMode.wrappedValue.dismiss()
onHide?()
}
}
}
}
}
First I press the button “Present” and after that “Dismiss” and repeat the method a couple of occasions.
After I see “Present” once more I press the reminiscence inspector in XCode.
I see that an occasion of ChildViewStore leaked in reminiscence.
Is that this anticipated habits or a SwiftUI bug?