Post

Replies

Boosts

Views

Activity

Reply to SwiftUI crash in AlertBridge.preferencesDidChange(_:)
This crash happens when updating an alert item while the alert is shown. This bug is fixed in iOS 14. The following is a sample code to simulate the crash (Note that you shouldn't dismiss the first alert): struct MessageInfo: Identifiable {   let title: String   let message: String       var id: String {     "\(title)-\(message)"   } } struct ContentView: View {   @State private var messageInfo: MessageInfo?   var body: some View {     Text("Test Alert Updating")       .font(.largeTitle)       .alert(item: $messageInfo) { info in         let titleText = Text(info.title)         let messageText = Text(info.message)         let dismissButton = Alert.Button.default(Text("OK"))         return Alert(title: titleText,                message: messageText,                dismissButton: dismissButton)       }       .onAppear {         DispatchQueue.global(qos: .userInitiated).asyncAfter(deadline: .now().advanced(by: .seconds(1))) {           messageInfo = .init(title: "Alert 1", message: "Test Alert 1")         }                   DispatchQueue.global(qos: .userInitiated).asyncAfter(deadline: .now().advanced(by: .seconds(2))) {           messageInfo = .init(title: "Alert 2", message: "Test Alert 2")         }       }   } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’21