From 26c417ae6884ef2d5293d135cafdb2e8d03610ed Mon Sep 17 00:00:00 2001 From: Mauro Romito Date: Wed, 30 Sep 2026 15:15:50 +0200 Subject: [PATCH] Move AlertInfo's button types out of the generic type With Swift 6.4, the default value for AlertInfo.primaryButton warned that T's Hashable conformance may be isolated and can't be used in a main actor-isolated context. The nested AlertButton/AlertTextField types don't depend on T, so move them to top level as AlertInfoButton and AlertInfoTextField, and keep typealiases so existing call sites compile. Constraining T to SendableMetatype isn't possible as the synthesized Hashable conformances of our main actor-isolated alert enums are isolated. --- ElementX/Sources/Other/Extensions/Alert.swift | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/ElementX/Sources/Other/Extensions/Alert.swift b/ElementX/Sources/Other/Extensions/Alert.swift index 94e6355e7..8d53adddb 100644 --- a/ElementX/Sources/Other/Extensions/Alert.swift +++ b/ElementX/Sources/Other/Extensions/Alert.swift @@ -45,20 +45,10 @@ extension View { /// .alert(item: $context.alertInfo) /// ``` struct AlertInfo: Identifiable, AlertProtocol { - struct AlertButton: Identifiable { - let id = UUID() - let title: String - var role: ButtonRole? - let action: (() -> Void)? - } - - struct AlertTextField: Identifiable { - let id = UUID() - let placeholder: String - let text: Binding - let autoCapitalization: TextInputAutocapitalization - let autoCorrectionDisabled: Bool - } + // The button types live outside this generic type, otherwise the default + // primaryButton would need T's (possibly isolated) Hashable conformance. + typealias AlertButton = AlertInfoButton + typealias AlertTextField = AlertInfoTextField /// An identifier that can be used to distinguish one error from another. let id: T @@ -99,6 +89,21 @@ extension AlertInfo { } } +struct AlertInfoButton: Identifiable { + let id = UUID() + let title: String + var role: ButtonRole? + let action: (() -> Void)? +} + +struct AlertInfoTextField: Identifiable { + let id = UUID() + let placeholder: String + let text: Binding + let autoCapitalization: TextInputAutocapitalization + let autoCorrectionDisabled: Bool +} + extension View { func alert(item: Binding?>) -> some View { alert(item: item) { item in