localstorage
localstorage copied to clipboard
Saving/reading from LocalStorage just doing nothing.
Hello
{
bool initStart = true;
bool startExist = store.Exists("start");
if (!startExist)
{
initStart = true;
store.Store("start", true);
}
if (initStart)
{
store.Store<bool>("start", true);
store.Store<SingleUserData>("data", new SingleUserData { answers = new List<SingleUserAnswer>(), id = 1 });
}
else
{
var lastQuestion = store.Get<SingleUserData>("data");
int lastQuestionId = lastQuestion.answers.Select(x => x.answerId).LastOrDefault();
}
}
Even if i added manualy "key" and "value" your library can't see it. The same situation is when i try to save something (simply boolean) in storage.
Hi @kamilk91, if I simplify your sample it just works. See the example below. Also, all tests seem to prove the same.
// Store it
var key = "data";
store.Store<SingleUserData>(key, new SingleUserData { answers = new List<SingleUserAnswer>(), id = 42 });
// Fetch it
var target = store.Get<SingleUserData>(key);
// Prove it
Console.WriteLine(target.id); // Prints: 42
Can it be that you're expecting it to be stored every time you run the program? In that case, you have to call the .Persist() operation before the routine closes.