My app on AppStore got two crashes that look very similar.This crash seems to append when I call function that use a environnement object SubscriptionManager
.
By analysing the error stack I think It happens in the function safeAddExercice()
when I try to get self.subscriptionManager
that is the environnement object.
These are errors stacks :
That is the function safeAddExercice()
:
private func safeAddExercice() { if Exercice.canAddNew(for: self.subscriptionManager) { self.showExerciceAdd = true }else{ self.showMember = true } }
It's a function of ExerciceList
:
struct ExerciceList: View { //some other environnement objects... @EnvironmentObject var subscriptionManager: SubscriptionManager...}
ExerciceList
is an item of TabBar :
struct MainApp: View { //some other envObjects... @EnvironmentObject var subscriptionManager: SubscriptionManager ... var body: some View { UIKitTabView{ ExerciceList(selection: .constant(nil)) .environment(\.managedObjectContext, managedObjectContext) .environmentObject(userSettings) .environmentObject(subscriptionManager) .tab(title: NSLocalizedString("My exercises", comment: ""), image: "dumbell")...}}
SubscriptionManager
is instantiated in AppDelegate
:
var subscriptionManager: SubscriptionManager = { SubscriptionManager() }()
And pass to MainApp
in SceneDelegate
:
let subscriptionManager = (UIApplication.shared.delegate as! AppDelegate).subscriptionManager let contentView = MainApp().environment(\.managedObjectContext, context) .environmentObject(subscriptionManager)...
Crash appends both on iOS 13 and 14. I try to find a moment where I missed to inject object but I'm struggling a bit to find something.