When applying the .accessibilityIdentifier(_:) modifier to a SwiftUI TextField, the identifier is correctly added to the SwiftUI Accessibility Tree (visible in Accessibility Inspector), but it is not assigned to the accessibilityIdentifier property of the underlying UITextField instance.
This causes issues for developers who monitor global notifications, such as UITextField.textDidChangeNotification. When a notification is received, the object (the UITextField) has a nil identifier, making it impossible to programmatically determine which specific text field triggered the event.
Steps to Reproduce:
Create a SwiftUI view containing a TextField.
Apply .accessibilityIdentifier("TargetTextField") to that TextField.
Set up an observer (via NotificationCenter or onReceive) for UITextField.textDidChangeNotification.
Run the app and type into the text field.
Inspect the accessibilityIdentifier property of the UITextField object provided by the notification.
Expected Result: The UITextField.accessibilityIdentifier should be "TargetTextField".
Actual Result: The UITextField.accessibilityIdentifier is nil.
1
0
145