Hi,
I also had some problems with sheets and a Binding Bool in the past.
I would try two things.
Are you sure that the tmpEvent you set using showSheet() isn't returning an optional value that might be nil? you can try adding:
guard let tmpEvent = Event(context: viewContext) else{
print("found nil")
return
}
and if you see something in the log you know that it contains nil. This also prevents the sheet from being shown while the Event is nil.
In general I would avoid having optionals in your views because you always have to deal with optional values, or risking that your app is getting terminated because of force unwrapping.
If that doesn't work, try using an default value and see if it later on changes to the correct value. If this is the case, your sheet is presented before the event got an initial value...
Take care,
David
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: