将用户默认值绑定到不同的标识符

时间:2022-08-07 23:56:18

I have a preference pane bundle (it runs in the System Preferences). I designed the interface using Interface Builder where I binded a "start automatically" checkbox to the Shared User Defaults. This works great but it writes the preference to com.apple.systempreferences. I would like to keep my preferences in the com.example.mybundle defaults. How do I do this?

我有一个首选项窗格包(它在系统偏好设置中运行)。我使用Interface Builder设计了界面,我将“自动启动”复选框绑定到共享用户默认值。这很好但是它将首选项写入com.apple.systempreferences。我想在com.example.mybundle默认值中保留我的首选项。我该怎么做呢?

I suppose I need to add a User Defaults controller in Interface Builder but how can I tell it to map with com.example.mybundle?

我想我需要在Interface Builder中添加User Defaults控制器,但是如何告诉它使用com.example.mybundle进行映射?

Thank you all!

谢谢你们!

1 个解决方案

#1


You'll want to bind to an NSDictionaryController whose persistence is managed through -[NSUserDefaults persistentDomainForName:] and -[NSUserDefaults setPersistentDomain:forName:] although it's frankly just as easy to use +[NSDictionary dictionaryWithContentsOfFile:] and -[NSDictionary writeToFile:atomically:].

你想要绑定到一个NSDictionaryController,它的持久性通过 - [NSUserDefaults persistentDomainForName:]和 - [NSUserDefaults setPersistentDomain:forName:]进行管理,虽然它坦率地说同样易于使用+ [NSDictionary dictionaryWithContentsOfFile:]和 - [NSDictionary writeToFile:atomically :]。

#1


You'll want to bind to an NSDictionaryController whose persistence is managed through -[NSUserDefaults persistentDomainForName:] and -[NSUserDefaults setPersistentDomain:forName:] although it's frankly just as easy to use +[NSDictionary dictionaryWithContentsOfFile:] and -[NSDictionary writeToFile:atomically:].

你想要绑定到一个NSDictionaryController,它的持久性通过 - [NSUserDefaults persistentDomainForName:]和 - [NSUserDefaults setPersistentDomain:forName:]进行管理,虽然它坦率地说同样易于使用+ [NSDictionary dictionaryWithContentsOfFile:]和 - [NSDictionary writeToFile:atomically :]。