Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create Cocoa App Preferences for Mac?

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

like image 944
Cristian Avatar asked Apr 13 '12 21:04

Cristian


People also ask

Where is the app preference on Mac?

To change options for an app such as Mail or Safari, open the app, click the app's name in the menu bar, then choose Preferences.

Where are preferences in Xcode?

Click Xcode > Preferences > Accounts.

What is AppKit Apple?

AppKit contains the objects you need to build the user interface for a macOS app. In addition to drawing windows, buttons, panels, and text fields, it handles all the event management and interaction between your app, people, and macOS.


2 Answers

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.

like image 92
Vervious Avatar answered Oct 25 '22 21:10

Vervious


For the window itself, i would recommend the RHPreferences framework.

Available on GitHub. BSD Licensed.

Its a simple and easy Preferences window controller with multiple tabs for your next Mac application.

It also provides:

  • Auto resizing between different sized tab views (With animation)
  • Custom NSToolbarItem support
  • Persistence of the last used tab
  • Support for placeholder NSToolbarItems (eg NSToolbarFlexibleSpaceItemIdentifier & NSToolbarShowFontsItemIdentifier)
like image 35
Richard H. Avatar answered Oct 25 '22 22:10

Richard H.