Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binding to a ShortcutRecorder hosted in a NSUserDefaultsController forces v2 compatibility mode #152

Closed
nothes opened this issue Apr 27, 2023 · 3 comments

Comments

@nothes
Copy link

nothes commented Apr 27, 2023

I was trying to set up a shortcut recorder in our application preferences in a subclass of NSUserDefaultsController, but not binding directly to anything user preference related, and hit the warning:

os_trace_error("#Error The control is bound to NSUserDefaults but is not transformed into an allowed CFPreferences value");
NSLog(@"WARNING: Shortcut Recroder 2 compatibility mode enabled. Getters of objectValue and NSValueBinding will return an instance of NSDictionary.");

in SRRecorderControl.m:977 of SR 3.4.0 (-propagateValue:forBinding:). The check seems overly broad -- in this case there was no userDefaults value being bound to convert to a CFPreferences value, and a v3 binding should be just fine. indeed, when I commented out the check, everything worked properly.

As a work-around I bound to a different class, but this seems like it shouldn't be required.

@Kentzo
Copy link
Owner

Kentzo commented Apr 28, 2023

How come that your subclass of NSUserDefaultsController is not CFPreferences related? Please give me more context.

This check happens when the value is about to get propagated from SRRecorderControl to NSUserDefaults*. The latter can only handle Core Foundation and thus a transformer is required, hence the warning.

@nothes
Copy link
Author

nothes commented Apr 28, 2023

Sorry, badly worded, let me try again.

I have a class, GeneralPreferences, which is a subclass of NSUserDefaultsController. It has an associated xib, and an outlet to the shortcut recorder: @property (nonatomic) IBOutlet SRRecorderControl *quickEntryShortcutRecorder;

I attempted to bind it to an instance property SRShortcut *shortcut in my awakeFromNib, like so:

[_quickEntryShortcutRecorder bind:NSValueBinding toObject:self withKeyPath:OFValidateKeyPath(self, quickEntryShortcutValue) options:nil];

Nothing here should directly interact with an NSUserDefaults value, it should just update and read from my instance variable, and the fact that the variable is on a class that is an NSUserDefaultsDelegate seems irrelevant. I may be misunderstanding something, but I don't see what I could possibly transform in this instance to satisfy the requirement?

edit: thank you for your quick response, by the way!! :)

@Kentzo
Copy link
Owner

Kentzo commented Apr 28, 2023

You need to pass a transformer via the options argument of the -bind:… method (from the example in README.md):

NSDictionary *options = @{NSValueTransformerNameBindingOption: NSKeyedUnarchiveFromDataTransformerName};
[_quickEntryShortcutRecorder bind:NSValueBinding toObject:self withKeyPath:OFValidateKeyPath(self, quickEntryShortcutValue) options:options];

@Kentzo Kentzo closed this as completed Sep 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants