简体   繁体   中英

What is the purpose of the User Defaults Controller?

In Xcode, I'm making a Mac application in Objective-C. In designing my application's window, I realized there was an object called the User Defaults Controller in the Object Browser. What is this for? I know what the user defaults are, but what is the purpose of this in the object browser? What would be an example of when one would use this? Thanks!

The Controller's purpose is to bind your User Interface elements to the User Defaults .

As an example, you can have an NSTextField in your interface representing a configuration preference (for example default document title). You bind this to the User Defaults Controller. With this method the user can specify a default title that is being saved or updated automatically by the Cocoa Framework without writing a single line of code.

To to this, in IB put a controller and a textfield. In the bindings inspector, set the textfiled's String property to bind to the User Defaults Controller, set the Controller Key to values and set the Model Key Path to the key used in User Defaults.

Cocoa Bindings使用它来允许将UI元素绑定到NSUserDefaults

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM