Use realm database to store key value objects
This script (Swift 3) will allow you to use Realm database to save Key\Value pairs
The script uses the default configuration of realm. To change the target realm (unnecessary if you use the default realm):
KeyValue.realm = Realm(CustomRealmConfiguration)
The key must be a string, the value can be a string, int, float, double, bool, or a date. If the key already exists, its value will be updated
KeyValue.setString(key: "String Key", value: "Value1")
KeyValue.setInt(key: "Integer Key", value: 42)
KeyValue.setBool(key: "Boolean Key", value: true)
KeyValue.setDate(key: "Date Key", value: Date())
KeyValue.getString(key: "String Key")
KeyValue.getInt(key: "Integer Key")
// ......
return nil if the key is not found
KeyValue.keyExists(key: "Bool Key")
KeyValue.getObject(key: "Date Key").delete()