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
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.
Click Xcode > Preferences > Accounts.
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.
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.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With