Post

Replies

Boosts

Views

Activity

Reply to Does swiftUI .alert miss a completion handler?
In my app the object collecting errors and alerts (also from an external device) is a global singleton and cannot live only in the UI. Also this is very likely a problem with the UiKit viewcontroller that provides the Alert and its transition. The reference to the observed object is never lost - otherwise it wouldn't work with the delay. The real problem from my perspective is that the transition of the Alert that is not finished.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Dec ’22
Reply to Does swiftUI .alert miss a completion handler?
And here ist the Output I ge when the delay is remove... You could actually argue that .alert is not respecting SwiftUIs core principles of "One Truth" ;-) Next Message One Getting new state: true Getting new state: false Next Message Two Getting new state: true Getting new state: false Next Message Three 2022-12-05 09:15:21.280381+0100 Dummy[15473:8198016] [Presentation] Attempt to present <SwiftUI.PlatformAlertController: 0x13f052000> on <_TtGC7SwiftUI19UIHostingControllerGVS_15ModifiedContentVS_7AnyViewVS_12RootModifier__: 0x159814a00> (from <_TtGC7SwiftUI19UIHostingControllerGVS_15ModifiedContentVS_7AnyViewVS_12RootModifier__: 0x159814a00>) which is already presenting <SwiftUI.PlatformAlertController: 0x158037800>. Getting new state: true Getting new state: false Next Message Four 2022-12-05 09:15:24.429913+0100 Dummy[15473:8198016] [Presentation] Attempt to present <SwiftUI.PlatformAlertController: 0x13f052000> on <_TtGC7SwiftUI19UIHostingControllerGVS_15ModifiedContentVS_7AnyViewVS_12RootModifier__: 0x159814a00> (from <_TtGC7SwiftUI19UIHostingControllerGVS_15ModifiedContentVS_7AnyViewVS_12RootModifier__: 0x159814a00>) which is already presenting <SwiftUI.PlatformAlertController: 0x158037800>. Getting new state: true Getting new state: false Next Message Five 2022-12-05 09:15:27.584491+0100 Dummy[15473:8198016] [Presentation] Attempt to present <SwiftUI.PlatformAlertController: 0x13f052000> on <_TtGC7SwiftUI19UIHostingControllerGVS_15ModifiedContentVS_7AnyViewVS_12RootModifier__: 0x159814a00> (from <_TtGC7SwiftUI19UIHostingControllerGVS_15ModifiedContentVS_7AnyViewVS_12RootModifier__: 0x159814a00>) which is already presenting <SwiftUI.PlatformAlertController: 0x158037800>. Getting new state: true Getting new state: false
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Dec ’22
Reply to Does swiftUI .alert miss a completion handler?
Here is a little example of what I mean. If you take out the delay - it stops working: import Combine class Messages : ObservableObject { static var shared = Messages() @Published var isPresented:Bool = false @Published var message:String = "" var messages = ["One", "Two", "Three", "Four", "Five" ] var subscriptions:[AnyCancellable] = [] init() { $isPresented .delay(for: .seconds(1), scheduler: DispatchQueue.main) // <- Take out this delay and it stops working. .receive(on: DispatchQueue.main) .sink{ [weak self] state in print ("Getting new state: \(state)") if state == false { self?.next() DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(3)) { [weak self] in if self?.isPresented == true { self?.isPresented = false } } } } .store(in: &subscriptions) } func next() { if messages.isEmpty == false { self.message = messages.removeFirst() self.isPresented = true print ("Next Message \(self.message)") } } } @main struct DummyApp: App { @ObservedObject var messages = Messages.shared @State var isPresented = false var body: some Scene { WindowGroup { VStack { Button("isPresented: \(String(describing:messages.isPresented))"){ messages.isPresented = true } .frame(width:150, height:100) .alert("My Alert", isPresented: $isPresented, actions: { Button("OK"){} }, message:{ Text(messages.message) } ) .onReceive(messages.$isPresented){ state in isPresented = state } Color.clear .frame(width: 100,height: 300) } } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Dec ’22
Reply to iOS App/Designed for iPad crashing in Ventura - suspect LazyVGrid.
Forgot the error description...  *** Assertion failure in -[UICollectionViewData indexPathForItemAtGlobalIndex:], UICollectionViewData.mm:835 2022-11-22 15:03:07.448874+0100 CameraCompanionBETA[3997:41963] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'request for index path for global index 4 when there are only 4 items in the collection view'
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’22