Objective-c – How to create Cocoa App Preferences for Mac

cocoamacosobjective c

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.

EDIT: The following link is perfect for this: https://developer.apple.com/cocoa/cocoabindings.html

Best Answer

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.