Storing settings in Ti.App.Properties
Ti.App.Properties
should be used for storing application properties. Long string values can be stored as a property, which makes them very useful for storing stringified JSON data.
Strings, integers, doubles, and Boolean values can all be stored and accessed using the appropriate command. In the following example we are going to store a Boolean value for enabled_preference
. If the property does not exist, it will be automatically created.
if(!Ti.App.Properties.hasProperty('enabled_preference')) { Ti.App.Properties.setBool('enabled_preference', true); }
The code to retrieve the property is as follows:
Ti.App.Properties.getBool('enabled_preference', true);
Note
The second parameter getBool
is the default value to return if the property does not exist.