Save and Load Information for Mac

In Windows programming i would store information regarding my program in the Registry.

Is there a MAC desktop Xojo sample program that shows a simple method for saving and loading settings and information such as name, age etc ?

Save everything you need in a subfolder by your app name (com.mysoftwarehouse.myapp) in SpecialFolder.ApplicationData in whatever file format you want : csv, SQLite, pure text…

Incidentally, that method is cross platform, and access is faster than a bloated Registry.

???

https://en.wikipedia.org/wiki/MAC

If you want a macOS native solution, search for NSUserdefaults here on this forum or have a look at TT’s Smart Preferences in MacOSLib.

Indeed.
The common registry is /was a weakness of Windows.
All kinds of guff in one enormous file.

In recent years, the settings held in old INI files, and the settings held in ‘the registry’ have been farmed out to virtual versions by Windows.
That enforced a huge slow down on some older Windows 95/XP era apps that ‘did it the official way’ back then and suffer for it now.

having your settings in your appdata area should shield you from that, and Windows from you.

There is yet another reason to use appData : the pesky Registry optimizers, defragmenters and compression programs around. God forbid your precious settings may be erased or corrupted, and you end up with a very angry customer.

As Ulrich says you can use NSUserDefaults APIs either via a plug-in or declares. The upside to using defaults is that it’s fast, the downside is that it’s the Mac registry and can/does fail and is insecure.

Do not be tempted to read and write files directly in the preferences folder (which is how we used to do it when Dinosaurs still ruled the earth), this has been something Apple has tried to get us to stop for a long time, but in the last 4 years it can become an issue if you do.

As Michel says, the ApplicationData is the best place to read and write such settings if you don’t want to use the Mac registry. The easiest way to read/write a bunch of settings is to use a JSONItem item and write it out as a text file.

Years ago I needed exactly this type of thing… but did not want to have to support something “different” for Windows (registry) and macOS (plist)… so I reached back in time a bit and created a configuration system that is actually quite similar to the orignial Windows INI file… and it works on ALL Xojo platforms, and since the data is unique to a given application, there is no danger of corruption in a single file taking down all others .

And you don’t need to worry or care about datatypes, as it does all that for you

www.rdS.com/inifile.xojo_xml_project.zip

free to all

I really like the simplicity of MHPrefs.

I can assume that it uses “Mac registry” though

First time programming for Mac so im confused abit with how cleanup works if a user decides to move my app to the trash?

If the settings were stored in SpecialFolder.ApplicationData (com.mysoftwarehouse.myapp) are they removed as well?

[quote=332741:@Kevin Currie]
First time programming for Mac so im confused abit with how cleanup works if a user decides to move my app to the trash?
If the settings were stored in SpecialFolder.ApplicationData (com.mysoftwarehouse.myapp) are they removed as well?[/quote]

No… If you drag the APP to the trash… then then only that file is removed… any “data” including configurations remain unless removed manually

There is no such a thing as a “Mac Registry”… unlike Windows that “insists” you store all preference/option related data in one huge bloated file, macOS maintains a file for each app as required

Hate to argue with you man, but… The similarities are there, corrupted plist can take down the entire machine. Not to mention that the daemon responsible for saving and loading the the properties is a stinking pile’o’shite. It get’s itself corrupted sometimes and has to be restarted, otherwise no application on the system that uses NSUserDefaults preferences get saved. Even deleting the individual plist files no longer means that your preferences have been reset; which leads me conclude that NSUserDefaults is using a central ‘cache’ database and the plist files are simply for decoration.

Remember the Mac isn’t what it used to be; some would call this progress, I call it iOS with makeup.

cfprefsd
https://discussions.apple.com/thread/4958344?tstart=0

Unix with pretty lipstick instead of a terminal
Oh wait thats there too when you need it :stuck_out_tongue: