Autofilled password not working with bound value

I have a couple of NSTextFields values bound with corresponding string properties of my view controller class.
The NSTextFields have the content type set to Username and Password respectively.
When running, the user is asked to select the password and the values are apparently put in the text fields. But the bound properties are not set (they are empty strings). If I use stringValue directly from the text field the values are there.

The bound value is set to continuously update value.

I can work around this issue using stringValue, but I asume that autofill should also work with bindings on macOS.
Password AutoFill still doesn’t work with Cocoa bindings in macOS 11.3 beta 1 (20E5172i). I filed FB9007031.

There is a workaround—you can observe NSControlTextDidChangeNotifications from each textfield and manually update your string properties.

Example from my bug report:

Code Block objc
- (void)viewDidLoad {
    [super viewDidLoad];
    if (kEnableWorkaround) {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myControlTextDidChange:) name:NSControlTextDidChangeNotification object:self.usernameTextField];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myControlTextDidChange:) name:NSControlTextDidChangeNotification object:self.passwordTextField];
    }
}
/* these will also get called when typing; superfluous when already using bindings */
- (void)myControlTextDidChange:(NSNotification *)note {
    NSTextField *textField = (NSTextField *)note.object;
    if ([textField isEqual:self.usernameTextField]) {
        self.username = self.usernameTextField.stringValue;
    } else if ([textField isEqual:self.passwordTextField]) {
        self.password = self.passwordTextField.stringValue;
    }
}


…nor does it work in macOS 11.3 beta 2 (20E5186d)
Autofilled password not working with bound value
 
 
Q