Preferences

What is the best way to implement Prefereces into a program.

I wish the user to be able to specify

  1. Currency type Pounds, Dollars and Euro’s
  2. Measurement type Metric or Imperial
  3. Temperature type Celcius or Faranheit

Thanks Shane

you mean to store?
There you can for example use a SQLite database.

With the right plugins/declares you can extract these from the System. On the Mac look for NSLocale. Then these are controlled by System Preferences (on the Mac).

Otherwise, The easiest way is to store these in a text file in the application support folder (don’t use the preferences folder as this is no longer a recommended location for preference files).

The other way to store these is to use NSUserDefaults on the Mac and the Windows Registry on Windows. Again you should be able to find code for doing this. Xojo has a built-in registry class, but not NSUserDefaults, I think Christian has this as so does the MacOSLib.

NSUserDefaultsMBS class is there.

But we also include with plugins a sample to use SQLite database for cross platform preferences store with key/value.

[quote=122710:@Shane Rampling]Measurement type Metric or Imperial
Temperature type Celcius or Faranheit[/quote]
Are these values still in use in 2014 (legal) ?
Imperial and Faranheit

[quote=122731:@Emile Schwarz]Are these values still in use in 2014 (legal) ?
Imperial and Faranheit[/quote]

Don’t be fooled by the metric system universality. In the US, Farenheit is still the commonly accepted way to measure temperature.

Even in France, birth country of the metric system, you will hear people in the market request “une livre de carottes” (one pound of carrots). Habits are difficult to break. In the US, the metric system has been adopted in 1893 as standard. To this day, Americans still use feet, inches, yards, pounds, gallons and ounces. http://en.wikipedia.org/wiki/Metrication_in_the_United_States

Imperial Measurement is still extremely common in all the former Bristish Empire countries but Canada http://en.wikipedia.org/wiki/Imperial_measurement

a pound in Germany is just another way to say 500 grams.
Like a dozen for 12. People can’t forget those old things.

[quote=122710:@Shane Rampling]What is the best way to implement Prefereces into a program.

I wish the user to be able to specify

  1. Currency type Pounds, Dollars and Euro’s
  2. Measurement type Metric or Imperial
  3. Temperature type Celcius or Faranheit

Thanks Shane[/quote]
MacOSLib has a module called TTs Smart Preferences. It works on OS X, Window and Linux and it’s Mac App Store compliant. It literally couldn’t be easier. Typically you use it like this:

prefs.value ("Currency") = "Pounds"

To read the value back in, you also pass in a default value (in case it hasn’t been set yet).

if prefs.value("Currency", "Euros") then msgbox"Currency is Pounds because we already set it" end if

Non metric systems -> US, Liberia, Myanmar.

Ducking… sorry, couldn’t resist.

There are many ways. This blog post covers some of them:

Saving Preferences

[quote=122731:@Emile Schwarz]Are these values still in use in 2014 (legal) ?
Imperial and Faranheit[/quote]
You bet
In the USA - and by way of spillover to Canada and probably Mexico too

[quote=122736:@Michel Bujardet]
Imperial Measurement is still extremely common in all the former Bristish Empire countries but Canada http://en.wikipedia.org/wiki/Imperial_measurement[/quote]
And still used in a LOT of areas on a wily basis in Canada
Construction trades use imperial a LOT

Here in Taiwan, you’ll still find occasionally the traditional measurements for things, such as when it comes to property (land or houses), they’re measured in Ping and Fen. TVs and computer monitors are measured in inches.

Heck even time is still measured in imperial!

[quote=123093:@Sam Rowlands]Here in Taiwan, you’ll still find occasionally the traditional measurements for things, such as when it comes to property (land or houses), they’re measured in Ping and Fen. TVs and computer monitors are measured in inches.

Heck even time is still measured in imperial![/quote]

The geometric degree is the overwhelming common way of measuring angles, instead of the unusual metric Grad.

[quote=122743:@Gavin Smith]MacOSLib has a module called TTs Smart Preferences. It works on OS X, Window and Linux and it’s Mac App Store compliant. It literally couldn’t be easier. Typically you use it like this:

prefs.value ("Currency") = "Pounds"

To read the value back in, you also pass in a default value (in case it hasn’t been set yet).

if prefs.value("Currency", "Euros") then msgbox"Currency is Pounds because we already set it" end if[/quote]
How would I use it to change a boolean in com.apple.dock.plist?
And to set up MacOSLib, I saw that TTs Smart Preferences in separate, inside Additional Modules. So do I need to copy the macoslib folder too?

Figured out Q2. What about Q1?

Please note that using the Mac OS lib ties you down to producing 32bit applications. Which is why I am abandoning TT Smart Prefs right now. With a heavy heart.

Maximilian, there’s no need to abandon TT Smart Prefs due to minor 64-bit issues. These can be easily fixed. Have a look at latest issues and pull requests on macoslib GitHub pages:

https://github.com/macoslib/macoslib/issues/195

https://github.com/macoslib/macoslib/pull/196

If I do decide to use it, how would I use it to change a boolean in com.apple.dock.plist?

I still use classPreferences even in my 64bit App Store Apps.