Our DatabaseService needs to provide several things:
- A persistent store to save and retrieve any data our app needs.
- It should allow any type of data to be stored; however, we will specifically want it to handle JSON serialization.
- Static keys of all the data we will want to store.
- A static reference to a saved user? Well, yes it could. However, this brings up a point that we will address in a moment.
Regarding the first item, we can use NativeScript's application-settings module. Under the hood, this module provides a consistent API to work with two native mobile APIs:
- iOS: NSUserDefaults: https://developer.apple.com/reference/foundation/userdefaults
- Android: SharedPreferences: https://developer.android.com/reference/android/content/SharedPreferences.html ...