UserSettings
Overview
Represents a configuration file.
UserSettings is a singleton class, use Default
method to get access to an instance of the class.
Use case
You can use UserSettings class when you need to store preferences, for example:
method SaveSettings;
begin
Sugar.UserSettings.Default.Write("StoreLoginName", true);
Sugar.UserSettings.Default.Write("LastLoginName", "User");
Sugar.UserSettings.Default.Save;
end;
method LoadSettings;
begin
writeLn(Sugar.UserSettings.Default.Read("StoreLoginName", false));
writeLn(Sugar.UserSettings.Default.Read("LastLoginName", ""));
end;
Output:
True
User
Location
- Reference: Sugar
- Namespace: Sugar
Clear mapped
Removes all settings.
method Clear
void Clear()
func Clear()
void Clear()
Sub Clear()
Default
Returns default instance of the class.
class method Default: UserSettings
static UserSettings Default()
static func Default() -> UserSettings
static UserSettings Default()
Shared Function Default() As UserSettings
Keys
Gets a list of all keys stored in settings.
property Keys: array of String read;
String[] Keys { get; }
var Keys: String... { get{} }
String[] Keys { __get; }
ReadOnly Property Keys() As String()
Reads a setting with specified key. If setting with that key can not be found then specified default value is returned.
method Read(Key: String; DefaultValue: String): String
String Read(String Key, String DefaultValue)
func Read(_ Key: String, _ DefaultValue: String) -> String
String Read(String Key, String DefaultValue)
Function Read(Key As String, DefaultValue As String) As String
Parameters:
- Key: The key for a setting.
- DefaultValue: The default value for a setting.
Reads a setting with specified key. If setting with that key can not be found then specified default value is returned.
method Read(Key: String; DefaultValue: Boolean): Boolean
Boolean Read(String Key, Boolean DefaultValue)
func Read(_ Key: String, _ DefaultValue: Boolean) -> Boolean
Boolean Read(String Key, Boolean DefaultValue)
Function Read(Key As String, DefaultValue As Boolean) As Boolean
Parameters:
- Key: The key for a setting.
- DefaultValue: The default value for a setting.
Reads a setting with specified key. If setting with that key can not be found then specified default value is returned.
method Read(Key: String; DefaultValue: Double): Double
Double Read(String Key, Double DefaultValue)
func Read(_ Key: String, _ DefaultValue: Double) -> Double
Double Read(String Key, Double DefaultValue)
Function Read(Key As String, DefaultValue As Double) As Double
Parameters:
- Key: The key for a setting.
- DefaultValue: The default value for a setting.
Reads a setting with specified key. If setting with that key can not be found then specified default value is returned.
method Read(Key: String; DefaultValue: Int32): Int32
Int32 Read(String Key, Int32 DefaultValue)
func Read(_ Key: String, _ DefaultValue: Int32) -> Int32
Int32 Read(String Key, Int32 DefaultValue)
Function Read(Key As String, DefaultValue As Int32) As Int32
Parameters:
- Key: The key for a setting.
- DefaultValue: The default value for a setting.
Remove mapped
Removes a setting with a specified key.
method Remove(Key: String)
void Remove(String Key)
func Remove(_ Key: String)
void Remove(String Key)
Sub Remove(Key As String)
Parameters:
- Key: The key for a setting.
Save mapped
Causes any buffered data to be written to a settings storage.
method Save
void Save()
func Save()
void Save()
Sub Save()
Writes a setting with specified key and value. If setting with that key already exists then its value is overriden.
method Write(Key: String; Value: String)
void Write(String Key, String Value)
func Write(_ Key: String, _ Value: String)
void Write(String Key, String Value)
Sub Write(Key As String, Value As String)
Parameters:
- Key: The key for a setting.
- Value: The value for a setting.
Writes a setting with specified key and value. If setting with that key already exists then its value is overriden.
method Write(Key: String; Value: Boolean)
void Write(String Key, Boolean Value)
func Write(_ Key: String, _ Value: Boolean)
void Write(String Key, Boolean Value)
Sub Write(Key As String, Value As Boolean)
Parameters:
- Key: The key for a setting.
- Value: The value for a setting.
Writes a setting with specified key and value. If setting with that key already exists then its value is overriden.
method Write(Key: String; Value: Double)
void Write(String Key, Double Value)
func Write(_ Key: String, _ Value: Double)
void Write(String Key, Double Value)
Sub Write(Key As String, Value As Double)
Parameters:
- Key: The key for a setting.
- Value: The value for a setting.
Writes a setting with specified key and value. If setting with that key already exists then its value is overriden.
method Write(Key: String; Value: Int32)
void Write(String Key, Int32 Value)
func Write(_ Key: String, _ Value: Int32)
void Write(String Key, Int32 Value)
Sub Write(Key As String, Value As Int32)
Parameters:
- Key: The key for a setting.
- Value: The value for a setting.
Keys
Gets a list of all keys stored in settings.
property Keys: array of String read;
String[] Keys { get; }
var Keys: String... { get{} }
String[] Keys { __get; }
ReadOnly Property Keys() As String()
Default
Returns default instance of the class.
class method Default: UserSettings
static UserSettings Default()
static func Default() -> UserSettings
static UserSettings Default()
Shared Function Default() As UserSettings
Clear mapped
Removes all settings.
method Clear
void Clear()
func Clear()
void Clear()
Sub Clear()
Reads a setting with specified key. If setting with that key can not be found then specified default value is returned.
method Read(Key: String; DefaultValue: String): String
String Read(String Key, String DefaultValue)
func Read(_ Key: String, _ DefaultValue: String) -> String
String Read(String Key, String DefaultValue)
Function Read(Key As String, DefaultValue As String) As String
Parameters:
- Key: The key for a setting.
- DefaultValue: The default value for a setting.
Reads a setting with specified key. If setting with that key can not be found then specified default value is returned.
method Read(Key: String; DefaultValue: Boolean): Boolean
Boolean Read(String Key, Boolean DefaultValue)
func Read(_ Key: String, _ DefaultValue: Boolean) -> Boolean
Boolean Read(String Key, Boolean DefaultValue)
Function Read(Key As String, DefaultValue As Boolean) As Boolean
Parameters:
- Key: The key for a setting.
- DefaultValue: The default value for a setting.
Reads a setting with specified key. If setting with that key can not be found then specified default value is returned.
method Read(Key: String; DefaultValue: Double): Double
Double Read(String Key, Double DefaultValue)
func Read(_ Key: String, _ DefaultValue: Double) -> Double
Double Read(String Key, Double DefaultValue)
Function Read(Key As String, DefaultValue As Double) As Double
Parameters:
- Key: The key for a setting.
- DefaultValue: The default value for a setting.
Reads a setting with specified key. If setting with that key can not be found then specified default value is returned.
method Read(Key: String; DefaultValue: Int32): Int32
Int32 Read(String Key, Int32 DefaultValue)
func Read(_ Key: String, _ DefaultValue: Int32) -> Int32
Int32 Read(String Key, Int32 DefaultValue)
Function Read(Key As String, DefaultValue As Int32) As Int32
Parameters:
- Key: The key for a setting.
- DefaultValue: The default value for a setting.
Remove mapped
Removes a setting with a specified key.
method Remove(Key: String)
void Remove(String Key)
func Remove(_ Key: String)
void Remove(String Key)
Sub Remove(Key As String)
Parameters:
- Key: The key for a setting.
Save mapped
Causes any buffered data to be written to a settings storage.
method Save
void Save()
func Save()
void Save()
Sub Save()
Writes a setting with specified key and value. If setting with that key already exists then its value is overriden.
method Write(Key: String; Value: String)
void Write(String Key, String Value)
func Write(_ Key: String, _ Value: String)
void Write(String Key, String Value)
Sub Write(Key As String, Value As String)
Parameters:
- Key: The key for a setting.
- Value: The value for a setting.
Writes a setting with specified key and value. If setting with that key already exists then its value is overriden.
method Write(Key: String; Value: Boolean)
void Write(String Key, Boolean Value)
func Write(_ Key: String, _ Value: Boolean)
void Write(String Key, Boolean Value)
Sub Write(Key As String, Value As Boolean)
Parameters:
- Key: The key for a setting.
- Value: The value for a setting.
Writes a setting with specified key and value. If setting with that key already exists then its value is overriden.
method Write(Key: String; Value: Double)
void Write(String Key, Double Value)
func Write(_ Key: String, _ Value: Double)
void Write(String Key, Double Value)
Sub Write(Key As String, Value As Double)
Parameters:
- Key: The key for a setting.
- Value: The value for a setting.
Writes a setting with specified key and value. If setting with that key already exists then its value is overriden.
method Write(Key: String; Value: Int32)
void Write(String Key, Int32 Value)
func Write(_ Key: String, _ Value: Int32)
void Write(String Key, Int32 Value)
Sub Write(Key As String, Value As Int32)
Parameters:
- Key: The key for a setting.
- Value: The value for a setting.