PSPreferenceController
Declarative panes, described by a Root.plist, need none of this.
Adopt this protocol when your pane is a view controller you wrote yourself
and you need to know which domain to write to and when the pane is on screen.
Include
#import "PSPreferenceController.h"
Protocol
Signature
@protocol PSPreferenceController <NSObject> - (void)setPreferencesDomain:(NSString *)domain; - (void)preferencesDidAppear; - (void)preferencesDidDisappear; @end
| Method | When it is called |
|---|---|
setPreferencesDomain: |
Before the pane is shown. The domain comes from the defaults
key in your bundle's Info.plist, so the app decides it and
the pane does not have to hardcode it.
|
preferencesDidAppear |
The pane became visible. Reload from disk here: the tweak may have written since. |
preferencesDidDisappear |
The pane went away. Flush anything unsaved. |
Example
Objective-C
@interface MyPrefsController : NSViewController <PSPreferenceController>
@end
@implementation MyPrefsController {
PSUserDefaults *_prefs;
}
- (void)setPreferencesDomain:(NSString *)domain {
_prefs = [[PSUserDefaults alloc] initWithSuiteName:domain];
}
- (void)preferencesDidAppear {
self.toggle.state = [_prefs boolForKey:@"enabled"] ? NSControlStateValueOn
: NSControlStateValueOff;
}
- (void)preferencesDidDisappear {
[_prefs synchronize];
}
@end
See also
Preference Bundles for packaging the pane so the app finds it.