Cristian Cristian - 2 months ago 8x
Objective-C Question

XCode Cocoa App Preferences?

Sorry if this seems like a stupid question, but i've spent the last half hour searching the Internet and can't find an answer to my question. I'm hoping this is because I've missed something really simple.

I have created a simple app in XCode for Mac, it builds and compiles fine.

How do I create a menu for preferences? Is there an easy way or do i have to create a new interface? How do I then get and put values into these preferences?

I did find one tutorial but it was for iOS, and from what I can see the 'Settings bundle' isn't available if you're developing for Mac.

Thanks in advance.

EDIT: The following link is perfect for this:


This is the documentation you want. More specifically How to provide a Preferences Interface.

Anyhow, you'll have to make your own preferences menu/window as you would make any other window, and have some controls that allow modifying values that are then stored in the User Defaults dictionary, which is where user preferences are usually stored (a process which Cocoa Bindings makes extremely easy).

Otherwise, manually, you would probably want a reference to [NSUserDefaults standardUserDefaults] so you can -setObject:ForKey: and so forth. It would be wise to read the entire documentation linked to above (including the other sections).

For more information on how Cocoa Bindings can be used to interface with NSUserDefaults to store/retrieve preferences, see the Apple docs here.