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.
This commit is contained in:
Mauro Romito
2026-09-30 15:15:50 +02:00
committed by Mauro
parent 831234865b
commit 26c417ae68
+19 -14
View File
@@ -45,20 +45,10 @@ extension View {
/// .alert(item: $context.alertInfo)
/// ```
struct AlertInfo<T: Hashable>: 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<String>
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<String>
let autoCapitalization: TextInputAutocapitalization
let autoCorrectionDisabled: Bool
}
extension View {
func alert<T: Hashable>(item: Binding<AlertInfo<T>?>) -> some View {
alert(item: item) { item in